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

Measure to calculate with filters MAX()

HI 

Have a table that looks like this :

 

I'm looking for a measure that will only sum the cost for each PO that have the latest version number .

 

So for example I want to have the value for Metro I want to have the cost of 5486 .

 

I know that I should use the MAX() function in some way

 

Supplier                PO              VersionCost

Metro12390570486
Metro123905704614
Metro12390572486
Metro123905725000
Metro146140404300
OFFICE           15544130225
OFFICE           15575580357
OFFICE           15588010396
OFFICE           15649380238
OFFICE           1614940060
OFFICE           16149400264
OFFICE           16149400233,1
OFFICE           161494005425
OFFICE           16149400874,8
OFFICE           16149400400
OFFICE           1614940054
OFFICE           16149400620
OFFICE           1614940160
OFFICE           16149401264
OFFICE           16149401250
OFFICE           16149401600
OFFICE           1614940110000
OFFICE           16149401400
OFFICE           1614940154
OFFICE           16149401620

 

2 ACCEPTED SOLUTIONS
v-juanli-msft
Community Support
Community Support

Hi @Oleander 

Create measures

Capture1.JPG

Measure =
VAR lastversion =
    CALCULATE (
        MAX ( 'Table'[Version] ),
        ALLEXCEPT (
            'Table',
            'Table'[Supplier],
            'Table'[PO]
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Cost] ),
        FILTER (
            ALLEXCEPT (
                'Table',
                'Table'[Supplier],
                'Table'[PO]
            ),
            'Table'[Version] = lastversion
        )
    )

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

Hi!

I used your DAX formula to this :

VAR Lastversion:=CALCULATE(MAX(Tabell1[Version]);ALLEXCEPT(Tabell1;Tabell1[Leverantör];Tabell1[PO]))

and

Return:=CALCULATE(SUM(Tabell1[Kost]);FILTER(ALLEXCEPT(Tabell1;Tabell1[Leverantör];Tabell1[PO]);Tabell1[Version]=[VAR Lastversion]))

 

Is there any faults in this code ?

View solution in original post

6 REPLIES 6
Oleander
Frequent Visitor

Found a solution that fitted my table :

CALCULATE(SUM(DBASE[Cost]);FILTER(DBASE;DBASE[Version] =CALCULATE (MAX(DBASE[Version]);FILTER(DBASE;DBASE[Supplier]))))

😎

v-juanli-msft
Community Support
Community Support

Hi @Oleander 

Create measures

Capture1.JPG

Measure =
VAR lastversion =
    CALCULATE (
        MAX ( 'Table'[Version] ),
        ALLEXCEPT (
            'Table',
            'Table'[Supplier],
            'Table'[PO]
        )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Cost] ),
        FILTER (
            ALLEXCEPT (
                'Table',
                'Table'[Supplier],
                'Table'[PO]
            ),
            'Table'[Version] = lastversion
        )
    )

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Hi Maggie !

Thanks for your reply:

I've tryed your DAX now but I get the same result when I try my own DAX formula when I in the Pivot delete the PO column :

Sista PO=SUMX(FILTER(Tabell1;Tabell1[Version] = MAX(Tabell1[Version]));Tabell1[Kost])

 

If I deselect the "PO" column so that I only have Supplier and Return, it will only show the latest/Highest PO sum for that supplier.

Metro will show "5486" and not "9786" ((PO 1239057) 5486 + (PO 1461404)  4300)

 

Kind regards

OleanderNamnlös.jpg

Hi!

I used your DAX formula to this :

VAR Lastversion:=CALCULATE(MAX(Tabell1[Version]);ALLEXCEPT(Tabell1;Tabell1[Leverantör];Tabell1[PO]))

and

Return:=CALCULATE(SUM(Tabell1[Kost]);FILTER(ALLEXCEPT(Tabell1;Tabell1[Leverantör];Tabell1[PO]);Tabell1[Version]=[VAR Lastversion]))

 

Is there any faults in this code ?

Hi !

 

If I only use the one of the AllExept() formulas , it will work, not with both.

=CALCULATE(SUM(Tabell1[Kost]);FILTER(ALLEXCEPT(Tabell1;Tabell1[Leverantör]);Tabell1[Version]=[Lastversion]))

Thanks

 

Solved.jpg

//Göran

Greg_Deckler
Super User
Super User

https://community.powerbi.com/t5/Quick-Measures-Gallery/Lookup-Min-Max/td-p/985814


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

Top Solution Authors
Top Kudoed Authors