0
votes

I have a problem with Power BI and I would like to get help. My table is like this

Branch Year Sales Share of Sales
Maca 2019 13K
Abdo 2019 10K
Weto 2020 15K
Roro 2020 30K
Roro 2019 10K

On the Share of sales column, I will divide sales by sum of sales. But I need it to be dynamic as When I choose 2019 on visual slicer, The column should divide the sales by the sum of Sales column filtered to 2019. The same way, when I choose 2019 and Roro branch on the slicer, the numbers need to be divided by sum of sales filtered to 2019 and Roro branch. In a nutshell, the denominator should be dynamic with visual slicers. I used the method of ISFILTERED function with sum aggregate measure, but It didn't work for me. I would be happy if you can help me with this issue. Thanks beforehand.

1

1 Answers

2
votes

You need a measure like this (where Table is the name of your table):

Share of Sales = SUM('Table'[Sales]) / SUMX(ALLSELECTED('Table'), 'Table'[Sales])

So if there is no filter applied, it will look like this:

enter image description here

When it is filtered by year, like this:

enter image description here

And when it is filtered by year and branch, like this:

enter image description here

ALLSELECTED function will remove the context filters, but will retain the explicit filters (e.g. slicers), so SUMX(ALLSELECTED('Table'), 'Table'[Sales]) will give you the total sales of the all the data shown at this moment. SUM('Table'[Sales]) on the other hand will calculate the total sales in the current context, i.e. data row or totals row.