Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I am new to this community and new to Power BI, so please let me know if there is already information available to help me figure this one out on my own. I've searched for a solution the last few days, but I haven't been able to find it, yet.
I used sample data to create the following matrix:
I would like to include a column that shows a running percentage of countries in each segment that updates with slicers that filter year and/or month:
Could someone please point me in the right direction? Any assistance would be greatly appreciated.
Here is my pbix with sample data: ABCexample.pbix
Here is the Excel file that has the setup I am looking for: pivotABC.xlsx
Solved! Go to Solution.
Happy to help!
Yes, changing the sort order requires the measure to be adjusted. Here the measure is based on gross sales (from high to low).
% Running Total in Country v2 =
VAR CurrentCountry =
SELECTEDVALUE ( Sheet1[Country] )
VAR AllCountries =
ALLSELECTED ( Sheet1[Country] )
VAR RankCountries =
ADDCOLUMNS (
AllCountries,
"@Rank", RANKX ( AllCountries, CALCULATE ( SUM ( Sheet1[Gross Sales] ) ),, DESC )
)
VAR CurrentRank =
MAXX ( FILTER ( RankCountries, Sheet1[Country] = CurrentCountry ), [@Rank] )
VAR RunningSales =
SUMX (
FILTER ( RankCountries, [@Rank] <= CurrentRank ),
CALCULATE ( SUM ( Sheet1[Gross Sales] ) )
)
VAR TotalSales =
CALCULATE ( SUM ( Sheet1[Gross Sales] ), REMOVEFILTERS ( Sheet1[Country] ) )
VAR Result =
DIVIDE ( RunningSales, TotalSales )
RETURN
Result
If you want it from low to high, please rewrite 'DESC' in the code to 'ASC'.
This should be your result:
Hey,
Give this measure a try:
% Running Total in Country =
VAR CurrentRank =
SELECTEDVALUE ( Sheet1[Country] )
VAR RunningSales =
CALCULATE (
SUM ( Sheet1[Gross Sales] ),
REMOVEFILTERS ( Sheet1[Country] ),
Sheet1[Country] <= CurrentRank
)
VAR TotalSales =
CALCULATE ( SUM ( Sheet1[Gross Sales] ), REMOVEFILTERS ( Sheet1[Country] ) )
VAR Result =
DIVIDE ( RunningSales, TotalSales )
RETURN
Result
% Running Total is always based on alphabetical order of the countries. Is this what you want?
Thank you so much for your reply!
I'm glad you brought up that the current setup was alphabetical by country. That was definitely a mistake on my part. My original data is ordered by Gross Sales descending and that is what I meant to do in my example. Your measure works perfectly for the scenario I posted.
Does changing the sorting require completely changing the logic of the measure? I'm playing with it now to see if I can do it myself, but haven't figured it out, yet.
Thank you, again.
Happy to help!
Yes, changing the sort order requires the measure to be adjusted. Here the measure is based on gross sales (from high to low).
% Running Total in Country v2 =
VAR CurrentCountry =
SELECTEDVALUE ( Sheet1[Country] )
VAR AllCountries =
ALLSELECTED ( Sheet1[Country] )
VAR RankCountries =
ADDCOLUMNS (
AllCountries,
"@Rank", RANKX ( AllCountries, CALCULATE ( SUM ( Sheet1[Gross Sales] ) ),, DESC )
)
VAR CurrentRank =
MAXX ( FILTER ( RankCountries, Sheet1[Country] = CurrentCountry ), [@Rank] )
VAR RunningSales =
SUMX (
FILTER ( RankCountries, [@Rank] <= CurrentRank ),
CALCULATE ( SUM ( Sheet1[Gross Sales] ) )
)
VAR TotalSales =
CALCULATE ( SUM ( Sheet1[Gross Sales] ), REMOVEFILTERS ( Sheet1[Country] ) )
VAR Result =
DIVIDE ( RunningSales, TotalSales )
RETURN
Result
If you want it from low to high, please rewrite 'DESC' in the code to 'ASC'.
This should be your result:
That did it! Thank you again!
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
94 | |
86 | |
82 | |
70 | |
49 |
User | Count |
---|---|
143 | |
125 | |
108 | |
60 | |
55 |