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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

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
Community Champion
Community Champion

Hi @Anonymous 

please use

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

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.