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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

SUMMARIZECOLUMNS (SQL to DAX)

Hello,

 

DATA: I have two columns CustomerID and SalesID.

 

GOAL:

I made a table visual in the screenshot below displaying CustomerID and Max(SalesID) where SalesID is above -1. That means, the table shows distinct CustomerID with the latest SalesID
Now, I want to do a distinct count on the Max(SalesID) column.

 

 

Natalie123455_0-1709103207848.png

 

HOW I WOULD SOLVE THIS IN SQL:

select CustomerID, max(SalesID)

from [table]

where SalesID > -1

group by CustomerID

 

Based on this table, I would perform a distinct count on the column max (SalesID)

 

BUT IN DAX? 😞

However, I am unsure how to do it in DAX (I tried a lot with SUMMARIZECOLUMNS) and I looked at https://www.sqlbi.com/articles/from-sql-to-dax-filtering-data/ but I couldn't figure it out.

 

Do you have any hints on how to transform the SQL to DAX?

 

Many thanks and best,

Natalie

2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous, Try a measure like

 

Measure = Var _tab= SUMMARIZE('Table', 'Table'[CistomerId],"_1" ,Max('Table'[SalesID]))
return COUNTROWS(SUMMARIZE(_tab,[_1]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

View solution in original post

v-jingzhan-msft
Community Support
Community Support

Made a minor change to Amit's code to include the filter on SalesID

Measure =
VAR _tab =
    SUMMARIZE (
        'Table',
        'Table'[CistomerId],
        "_1", CALCULATE ( MAX ( 'Table'[SalesID] ), 'Table'[SalesID] > -1 )
    )
RETURN
    COUNTROWS ( SUMMARIZE ( _tab, [_1] ) )

View solution in original post

3 REPLIES 3
Anonymous
Not applicable

Many thanks to both of you! This works brilliant!

v-jingzhan-msft
Community Support
Community Support

Made a minor change to Amit's code to include the filter on SalesID

Measure =
VAR _tab =
    SUMMARIZE (
        'Table',
        'Table'[CistomerId],
        "_1", CALCULATE ( MAX ( 'Table'[SalesID] ), 'Table'[SalesID] > -1 )
    )
RETURN
    COUNTROWS ( SUMMARIZE ( _tab, [_1] ) )
amitchandak
Super User
Super User

@Anonymous, Try a measure like

 

Measure = Var _tab= SUMMARIZE('Table', 'Table'[CistomerId],"_1" ,Max('Table'[SalesID]))
return COUNTROWS(SUMMARIZE(_tab,[_1]))

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.