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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
Anonymous
Not applicable

Need Help With Dax Table Query

I have the below Dax measure that produces a list of parent suppliers with the sum of the spend on them from a fact table.

 

Parent Supl Spend = var parents = SUMMARIZE('Export','Export'[ParentSupplierName],'Export'[LeaderName],"Spend",SUM('Export'[Spend Amount]))
 
Return parents
 
The lines returned from one supplier look like this:
 
jjanecm_0-1661885885041.png

 

I would like to extract from this output ONLY the line with the GREATEST spend.   How would I do that?

 

Mark Janecek

PTP Metrics Analyst 

Johnson Controls

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to try this measure.

 

GROUP =
CALCULATE (
    MAX ( 'Parent Supl Spend'[Spend] ),
    ALLEXCEPT ( 'Parent Supl Spend', 'Parent Supl Spend'[ParentSupplierName] )
)

 

 

If you want to get max spend for each user in calcualted table, please try this code.

Parent Supl Spend =
VAR _Parent =
    SUMMARIZE (
        'Export',
        'Export'[ParentSupplierName],
        'Export'[LeaderName],
        "Spend", SUM ( 'Export'[Spend Amount] )
    )
VAR _MAX =
    SUMMARIZE (
        FILTER (
            _Parent,
            VAR _MaxSpend =
                MAXX (
                    FILTER ( _Parent, [ParentSupplierName] = EARLIER ( [ParentSupplierName] ) ),
                    [Spend]
                )
            RETURN
                [Spend] = _MaxSpend
        ),
        [ParentSupplierName],
        [LeaderName],
        [Spend]
    )
RETURN
    _MAX

 

Best Regards,
Rico Zhou

 

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

3 REPLIES 3
Anonymous
Not applicable

Thank you for the help!

The below code First returns 2 tables of supplier keys that have invoiced in one system or another.(aribainvs & fs2invs).

 

Then it returns a table of a union of those 2 results (_allinvs).  

 

I am trying to take the union and return every entry from the table named Supplier lookup that does NOT have a Supplier Key in the Union.  

 

My CALCULATETABLE Function is saying the _allinvs table variable can't be found.  I don't understand why?

 

EVALUATE
/*Retruns table of supplier keys that invoiced with Ariba*/
VAR aribainvs =
    SUMMARIZE (
        FILTER (
            'Onboarding Report',
            NOT (
                ISBLANK ( 'Onboarding Report'[Invoice Submit Date] )
            )
        ),
        'Onboarding Report'[SupplierKey]
    ) 
    
    /*Returns Table of supplier keys that Invoices with FS2*/
VAR fs2invs =
    DISTINCT ( 'FS2 Invoices'[SupplierKey] )
VAR _allinvs =
    UNION (
        aribainvs,
        fs2invs
    )
VAR noinvs =
    CALCULATETABLE (
        _allinvs,
        _allinvs[SupplierKey] <> 'Supplier Lookup'[SupplierKey]
    )
RETURN
    _allinvs

 

 

jjanecm_0-1662666451997.png

 

Anonymous
Not applicable

Hi @Anonymous ,

 

I suggest you to try this measure.

 

GROUP =
CALCULATE (
    MAX ( 'Parent Supl Spend'[Spend] ),
    ALLEXCEPT ( 'Parent Supl Spend', 'Parent Supl Spend'[ParentSupplierName] )
)

 

 

If you want to get max spend for each user in calcualted table, please try this code.

Parent Supl Spend =
VAR _Parent =
    SUMMARIZE (
        'Export',
        'Export'[ParentSupplierName],
        'Export'[LeaderName],
        "Spend", SUM ( 'Export'[Spend Amount] )
    )
VAR _MAX =
    SUMMARIZE (
        FILTER (
            _Parent,
            VAR _MaxSpend =
                MAXX (
                    FILTER ( _Parent, [ParentSupplierName] = EARLIER ( [ParentSupplierName] ) ),
                    [Spend]
                )
            RETURN
                [Spend] = _MaxSpend
        ),
        [ParentSupplierName],
        [LeaderName],
        [Spend]
    )
RETURN
    _MAX

 

Best Regards,
Rico Zhou

 

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

tamerj1
Super User
Super User

Hi @Anonymous 

please use

Parent Supl Spend =
TOPN (
    1,
    SUMMARIZE (
        'Export',
        'Export'[ParentSupplierName],
        'Export'[LeaderName],
        "Spend", SUM ( 'Export'[Spend Amount] )
    ),
    [Spend]
)

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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

Top Solution Authors