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
Dankang
Regular Visitor

simple dax question

Max.png

 

Hi All,

 

Hope anyone can help me with this.

 

I am trying to get Total number of O&A Display for only the highest callfilevisit ID for Each outlet. 

 

i.e outlet "1000245" will only need to show a value of 2 from callfilevisit ID "28232875" and so on, then sum all the values.

 

I have tried Max function but it only brings max callfilevisit ID for all outlets.

 

Any advice or help would be greatly appreciated.

1 ACCEPTED SOLUTION
Stachu
Community Champion
Community Champion

try this code

Measure =
VAR OutletsVisits =
    GROUPBY (
        'Table',
        'Table'[OutletId],
        "Callfilevisit ID", MAXX ( CURRENTGROUP (), [Callfilevisit ID] )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Total O&A Displays] ),
        TREATAS ( OutletsVisits, 'Table'[OutletId], 'Table'[Callfilevisit ID] )
    )

it gets the max callfilevisit per outlet and then calculates the sum of displays for these entries



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

View solution in original post

3 REPLIES 3
Stachu
Community Champion
Community Champion

try this code

Measure =
VAR OutletsVisits =
    GROUPBY (
        'Table',
        'Table'[OutletId],
        "Callfilevisit ID", MAXX ( CURRENTGROUP (), [Callfilevisit ID] )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[Total O&A Displays] ),
        TREATAS ( OutletsVisits, 'Table'[OutletId], 'Table'[Callfilevisit ID] )
    )

it gets the max callfilevisit per outlet and then calculates the sum of displays for these entries



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

Wow. This works perfectly. Thanks.

 

Could you please tell me why i need to use treatas function and what it does?

 

Cheers

Stachu
Community Champion
Community Champion

it passes the requested list of outlets & visits as a filter on the relevant fields
this article describes it in more detail
https://www.sqlbi.com/articles/propagate-filters-using-treatas-in-dax/



Did I answer your question? Mark my post as a solution!
Thank you for the kudos 🙂

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.