Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
jkaemmerling
Frequent Visitor

Calculating category share by month

Hi there,

 

I apologize if I misuse terms or am unaware of a feature availabe in DAX/Power BI as I suspect my issue may be additional data prep, but I'm completely stumped. I've linked the data file just in case and I need to show how the proportions of a given category change over time (by month) in a line chart that would show values like below:

 

                   Computer  Mobile    Tablet     Other

July47.22%49.92%2.67%0.19%
October48.81%48.66%2.36%0.17%

 

jkaemmerling_0-1629737345555.png

The only way I was able to show this was to use '% of row total' in excel 😭.

 

Key points:

  • I have a date table and I've created the relationship between dates on the date table and my main dataset.
  • My date table is continuous (from 01/2020 to 08/2021), but my main dataset is not
  • I have [Date] column in main dataset as Date type, "m/d/yyyy", [Month] as text and [Year] as numeric. [Month] and [Year] are not in use.
  • I am not using "show as % of grant total" feature on my visualization. 

 

I've tried three formulas for the calculated measure and they all don't work:

  1.  This makes all data points 100%

 

 

 

 

Count total for Month = DIVIDE(SUM(Combined[Count]),CALCULATE(SUM(Combined[Count]),FILTER('Date','Date'[Date].[Date])))

 

 

 

 

  • This gets an MdxScript error, below

 

 

 

 

Count total for Month = CALCULATE(SUM(Combined[Count]),Combined[Device])/COUNTROWS(Combined)​

 

 

 

 

 

 

 

Error Message:
MdxScript(Model) (6, 73) Calculation error in measure 'Combined'[Count total for Month]: Cannot convert value 'Computer' of type Text to type True/False. 

 

 

 

 

  • This works but does not provide the desired calculation (i.e.- totalling at month)  

 

 

 

 

Count total for Month = SUM(Combined[Count])/CALCULATE(SUM(Combined[Count]),ALLEXCEPT('Date','Date'[Date].[Date]))​

 

 

 

 

1 ACCEPTED SOLUTION
jkaemmerling
Frequent Visitor

Hi all,

 

@aj1973  was very close with the solution, but a friend and I worked it out to be the following:

DIVIDE(SUM(Combined[Count]),CALCULATE(SUM(Combined[Count]),ALL(Combined[Device])))
 
This can only work when there is a relationship between the date table and main data set ('Combined', in this case), because using the ALL function as a filter, allows you to keep the denominator (total device count in a given month) the same. 

View solution in original post

10 REPLIES 10
jkaemmerling
Frequent Visitor

Hi all,

 

@aj1973  was very close with the solution, but a friend and I worked it out to be the following:

DIVIDE(SUM(Combined[Count]),CALCULATE(SUM(Combined[Count]),ALL(Combined[Device])))
 
This can only work when there is a relationship between the date table and main data set ('Combined', in this case), because using the ALL function as a filter, allows you to keep the denominator (total device count in a given month) the same. 
jkaemmerling
Frequent Visitor

Hi Amine,

 

Apologies, I'm not doing a good job explaining myself. My goal would for the chart to look like the below but have the %'s add up to 100% for each month.

jkaemmerling_1-1629751816977.png

 

Is this close?

aj1973_0-1629751901284.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Yes that's the level of aggregraiton I need - but is it impossible to get it into a line chart?

Or do I have to create a secondary table (like the one you did) in Transform Data to feed these values? 

here is the file.

https://drive.google.com/drive/folders/1AZwUoX41Sqyt9AS_j5V_yGgw2udTsO8u?usp=sharing

 

The chart you sent was not clear to me. try it yourself 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Thank you very much for your help. Your contribution has sparked the solution I ultimately went with. 

 

A summary table needs to be created that (as you've shown) contains the device proportions out of each month and device. I thought PowerBI would have done that automatically, but I ended up creating the additional columns required in excel and re-uploading.

 

I'm sure there's a way to do it in Power BI but I'm not skilled enough. Thank you!

There is a way to do what in power bi?

 

Any way glad you made it

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

jkaemmerling
Frequent Visitor

Hi Amine,

 

Your calculation is adding all months to 100% - the desired calculation is for each month to be 100% AND for the devices to be xx% of that 100% in each month. Then we can see how each device % changes across each month.

aj1973
Community Champion
Community Champion

Hi @jkaemmerling 

Is this good?

aj1973_0-1629738771112.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

aj1973
Community Champion
Community Champion

Like this?

aj1973_0-1629750935633.png

 

Regards
Amine Jerbi

If I answered your question, please mark this thread as accepted
and you can follow me on
My Website, LinkedIn and Facebook

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.