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

Measure: calculation of %

Hello everyone!
Could you please help me with measure calculation of %.


I have data like this:
date                 product         amount        what I wish to do (like in excel) - %%
2020/04/21      apples           30                 30/900

2020/04/21      eggs              15                 15/900

2020/04/21      flour               900               900/900

2020/04/21     cinnamon     20                 20/900

 

And I need to find percentage of all product to flour. 

1 ACCEPTED SOLUTION
Icey
Community Support
Community Support

Hi @sadwick ,

 

Try this:

Measure =
VAR __Date =
    MAXX ( ALLSELECTED ( 'Table' ), 'Table'[date] )
VAR __Amount =
    CALCULATE (
        MAX ( 'Table'[Amount] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Product] ), 'Table'[Date] = __Date )
    )
VAR __Flour =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [product] = "flour" && [date] = __Date ),
        [amount]
    )
RETURN
    IF ( MAX ( 'Table'[Date] ) = __Date, DIVIDE ( __Amount, __Flour ) )

amount.PNG

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
camargos88
Community Champion
Community Champion

Hi @sadwick ,

 

Try this measure:

 

Measure =
VAR _flour = CALCULATE(SUM('Table'[amount ]); FILTER(ALL('Table'); 'Table'[product] = "flour"))
RETURN DIVIDE(SUM('Table'[amount ]); _flour)
 
Ricardo


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!



Greg_Deckler
Super User
Super User

Perhaps something like:

 

Measure = 
  VAR __Amount = MAX('Table'[amount])
  VAR __Flour = MAXX(FILTER('Table',[product] = "flour"),[amount])
RETURN
  DIVIDE(__Amount,__Flour)

@ 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...

@Greg_Deckler thanks!
But if this table is cumulative. And I need a percentage of all product to flour where date =max date?

date                 product         amount        what I wish to do (like in excel) - %%
2020/04/21      apples           30                 

2020/04/21      eggs              15                 

2020/04/21      flour               900             

2020/04/21     cinnamon       20               

2020/04/22     apples           60                 60/400

2020/04/22      eggs              9                  9/400

2020/04/22      flour               400             900/400

2020/04/22     cinnamon      60                 60/400

Icey
Community Support
Community Support

Hi @sadwick ,

 

Try this:

Measure =
VAR __Date =
    MAXX ( ALLSELECTED ( 'Table' ), 'Table'[date] )
VAR __Amount =
    CALCULATE (
        MAX ( 'Table'[Amount] ),
        FILTER ( ALLEXCEPT ( 'Table', 'Table'[Product] ), 'Table'[Date] = __Date )
    )
VAR __Flour =
    MAXX (
        FILTER ( ALLSELECTED ( 'Table' ), [product] = "flour" && [date] = __Date ),
        [amount]
    )
RETURN
    IF ( MAX ( 'Table'[Date] ) = __Date, DIVIDE ( __Amount, __Flour ) )

amount.PNG

 

 

Best Regards,

Icey

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

OK, so based on this Quick Measure: https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814

 

That would be something like:

 

Measure = 
  VAR __Date = MAX('Table'[date])
  VAR __Product = MAX('Table'[product]) //assumes product is in the visualization
  VAR __Amount = MAXX(FILTER('Table',[product] = __Product && [date] = __Date),[amount])
  VAR __Flour = MAXX(FILTER('Table',[product] = "flour" && [date] = __Date),[amount])
RETURN
  DIVIDE(__Amount,__Flour)

@ 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...

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.