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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
joiecy
Frequent Visitor

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
Frequent Visitor

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.

joiecy
Frequent Visitor

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] ) )

Regards
Zubair

Please try my custom visuals

his should definitely work

@joiecy

 

or your own MEASURE with this revision

 

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

Regards
Zubair

Please try my custom visuals

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


Regards
Zubair

Please try my custom visuals

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.