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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
joiecy
Advocate I
Advocate I

DAX measure to get percentage by group

i wanted to create a measure that can give me the daily rate of qty.

i have a table example like this:

DATETYPEQTY
1/1/2018Fruit2
1/1/2018Fruit3
1/1/2018Fruit1
1/1/2018Vege4
1/1/2018Vege5
1/1/2018Meat3
2/1/2018Vege4
2/1/2018Meat6
2/1/2018Meat1
2/1/2018Meat5
2/1/2018Fruit7
2/1/2018Fruit2

 

I wanted to get their daily rate such that the formula should be something like [sum(qty) of each type of each day] / [sum all (qty) of each day].

result table like this:

DATETYPEDAILY RATE
1/1/2018Fruit0.333333333
1/1/2018Vege0.5
1/1/2018Meat0.166666667
2/1/2018Fruit0.36
2/1/2018Vege0.16
2/1/2018Meat0.48

 

I tried this but the SUMX is getting the sum all of the entire table instead of each type

=SUM(qty)/SUMX(ALL(table), qty)

this is not working as well

=SUM(qty)/SUMX(VALUE(datetable[date]), qty)

how should i write the DAX formula to achieve this?

9 REPLIES 9
Anonymous
Not applicable

% of Total Sales:=([Total SalesAmount]) / CALCULATE([Total SalesAmount], ALLSELECTED(Sales[Category],Sales[SubCategory]))

OR 

% of Total Sales:=DIVIDE(([Total SalesAmount]) , CALCULATE([Total SalesAmount], ALLSELECTED(Sales[Category],Sales[SubCategory])))

 

WHERE Total Sales = SUM('Sales'[SalesAmount])

 

https://support.office.com/en-us/article/when-to-use-calculated-columns-and-calculated-fields-ca18d6...

joiecy
Advocate I
Advocate I

hi guys,

Appreciate your help again.

Extend to this scenario, lets say there are 2 levels of grouping.

DateGroupTYPEQTY
1/1/2018PlantFruit2
1/1/2018PlantFruit3
1/1/2018PlantFruit1
1/1/2018PlantVege4
1/1/2018PlantVege5
1/1/2018AnimalMeat3
2/1/2018PlantVege4
2/1/2018AnimalMeat6
2/1/2018AnimalMeat1
2/1/2018AnimalMeat5
2/1/2018PlantFruit7
2/1/2018PlantFruit2

 

is there a way where i can have a measure that can calculate the rate no matter i drill up to group or i drill down to type? how to combine this 2 dax?

= SUM ( 'animal and plant'[qty] ) / CALCULATE ( SUM ( 'animal and plant'[qty] ), ALL ( 'animal and plant'[Group] ) )

= SUM ( 'animal and plant'[qty] ) / CALCULATE ( SUM ( 'animal and plant'[qty] ), ALL ( 'animal and plant'[Type] ) )

 

thank you in advance.

nevermind guys, i got it already. as simple as just put 2 column in the ALL().

 

= SUM ( 'animal and plant'[qty] ) / CALCULATE ( SUM ( 'animal and plant'[qty] ), ALL ( 'animal and plant'[Type],  'animal and plant'[group] ) )

Zubair_Muhammad
Community Champion
Community Champion

@joiecy

 

tRY this one

 

=
SUM ( TableNmae[qty] )
    / CALCULATE ( SUM ( TableNmae[qty] ), ALL ( TableName[Type] ) )

his should definitely work

@joiecy

 

or your own MEASURE with this revision

 

=
SUM ( TableName[qty] )
    / SUMX ( VALUES ( datetable[date] ), CALCULATE ( SUM ( TableName[qty] ) ) )

thx @Zubair_Muhammad!

but both your suggestion return 1, which is not what i intended. 😞

HI @joiecy

 

It gives me correct results... I will try to upload the file

 

DAX Measure.png

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.