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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
jcastrod
Regular Visitor

% of Total by Week

Hey guys,

 

I've been digging around the forums today to try and find a solution, but can't quite find what I'm looking for.

 

I'm trying to make a sparkline of 3 categories of data and their "% contribution" to the total for each week (my x-axis).

 

The following is an example of my data:

 

WeekCategoryValue
1/1/2016A10
1/1/2016B20
1/1/2016C70
1/8/2016A70
1/8/2016B20
1/8/2016C10

 

 

I want to be able to have for the first week Category A = 10%, B = 20%, C = 70%, and for second week Category A = 70%, etc...

 

Using the "Percent of Grand Total" quick calc gives me the percent of the whole, not the week, which isn't helpful for my graph.

 

Anyone have any guidance or suggestions? I've considered a DAX formula possibly helping in this case.

 

I already forsee my future problem of actually charting it when I want 3 separate sparklines, one of each category, and that breaking the formula we put together in this post but...for another day!

 

Thanks!

8 REPLIES 8
Anonymous
Not applicable

I need help in same kind of problem. 
Here Column B is the correct calculation which is done by using built-in option to "show value as percentage of grand total", I need to create measure to get the same calculations, for which "D" I created using the dax-

DIVIDE(RETAIL_AUDIT_COMPETENCY_AUDITOR_DISTRIBUTION[Sum of No. of records],CALCULATE(SUM(RETAIL_AUDIT_COMPETENCY_AUDITOR_DISTRIBUTION[Column No. of records]),ALL(RETAIL_AUDIT_COMPETENCY_AUDITOR_DISTRIBUTION[WEEKDAY],RETAIL_AUDIT_COMPETENCY_AUDITOR_DISTRIBUTION[AUDIT_STATUS])))
but I am getting the incorrect value.
Note- B or D is calculated respective to Audit_Status and Weekday columns. 
Solution to this is much appreciated.

monty10_0-1640604732009.png

 

Greg_Deckler
Super User
Super User

Create a measure like this:

 

Measure = SUM([Value]) / SUMX(ALLEXCEPT(WeeklyCategories,WeeklyCategories[Week]),[Value])

Then a visual like this:

 

weeklycategories.png


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Thanks for the quick response!

 

I've thought of 2 things since reviewing your post:

 

1. It seems as though the formula you presented isn't given the correct percentages by week. If you see, C in week 2 is below 10%, when it should be 10% on the dot. It seems as though they are cut in half?

 

2. I've re-read my question, and think I presented my problem incorrectly. My data is really much more like as follows:

WeekIDValueCategory
1/1/2016110A
1/1/2016220A
1/1/2016320B
1/1/2016450C
1/8/2016590C
1/8/20166100C
1/8/2016710A
1/8/2016820B

 

What I'm actually driving towards is understanding my contributions of the categories, not by the categories. So in the data above, the value field is a means to drive the Category column (a conditional column I've established i.e. "If above x then A if above y then B etc..."). So what I would want to see in my week 1 data point is A = 50%, B = 25%, C = 25%, Week 2 etc... Does that make sense?

 

I really appreciate your help!

@jcastrod


What I'm actually driving towards is understanding my contributions of the categories, not by the categories. So in the data above, the value field is a means to drive the Category column (a conditional column I've established i.e. "If above x then A if above y then B etc..."). So what I would want to see in my week 1 data point is A = 50%, B = 25%, C = 25%, Week 2 etc... Does that make sense?


You can create a measure like below.

ContributionsOfCategories =
COUNTA ( TestTable[Category] )
    / CALCULATE (
        COUNTA ( TestTable[Week] ),
        ALLEXCEPT ( TestTable, TestTable[Week] )
    )

Then you should be able to use Line Chart to show it on the report.

lc.PNG

Regards

@v-ljerr-msft, thank you very much! This is so close to the solution I need.

 

I have double checked my formula to match yours, however, the values I'm getting are greater than 1...however, when I sum up for a given week the result divide by, say, one category's value, it comes out to the correct percentage. Does that make sense?

 

So for one week I get A = 4.2, B = 2.2, C = 1.1, which is odd. However, 4.2/(4.2+2.2+1.1) is the correct value I'm trying to display, so I know this is close...any thoughts?

@jcastrod


I have double checked my formula to match yours, however, the values I'm getting are greater than 1...


So could you share your formula and some sample data which can reproduce this issue in your case?

 

Regards

it is a row count by category you seek.   Is the total count for a week always 4 as per your example....or must the week row count also be established?

 

www.CahabaData.com

I believe a "count by week" must be established...if we can get that, then I think I can use a calc field to get my %total by category for each week, correct?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.