cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
shairado
Frequent Visitor

Get Sales Value from Table dependent on Max Date and multiple ID

Hi,

I am trying to use DAX to get the Sales value from a table, where I have multiple Sales line per ID, each one might have the same date, different date, or no date.

I am trying to only read the Sales values once per ID, where the Date is Max(Date).

 

This is the original table:

Table_1.PNG

 

 

 

 

 

And this is the result I am trying to achieve:

Table_2.PNG

 

 

 

I was able to use DAX to get the Maxdate (latest date) per ID:

Max Date =

CALCULATE(

MAX(‘Table’[Date]),

FILTER(‘Table’[Date]), EARLIER(‘Table’[ID]) = ‘Table’[ID])

)

 

Than, I tried using SUMX, with 2-filter criteria, but the formula below is giving an error:

Unique Sale =

CALCUALTE(

SUMX(‘Table’, ‘Table’[Sales]),

‘Table’[Date] = ‘Table’[Max Date]

&& ‘Table’[ID] = ‘Table’[ID]

)

 

Thanks for your time.

1 ACCEPTED SOLUTION

In case you have date table, you can get cumulative value like this. But in this case it might not work. But try out

 

Cumm Sales = CALCULATE([Sales],filter(date,date[date] <=maxx(date,date[date])))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

View solution in original post

3 REPLIES 3
amitchandak
Super User
Super User

Try

Measure = 
VAR __id = MAX ( 'Table'[ID] )
VAR __date = CALCULATE ( MAX( 'Table'[Date] ), ALLSELECTED ( 'Table' ),  'Table'[ID] = __id ) 
RETURN CALCULATE ( sum ( 'Table'[sales] ), VALUES ( 'Table'[ID] ), 'Table'[id] = __id, 'Table'[date] = __date )

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

@amitchandak  thanks, this measure works, I was hoping to use a Column (not a measure)

 

The second part, is creating a cummulative Visual, like with a table below:  

Table_3.PNG

 

 

Not sure how to create accumulative DAX using EARLIER and a Measure.

In case you have date table, you can get cumulative value like this. But in this case it might not work. But try out

 

Cumm Sales = CALCULATE([Sales],filter(date,date[date] <=maxx(date,date[date])))

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s.

Refer
https://radacad.com/creating-calendar-table-in-power-bi-using-dax-functions
https://www.archerpoint.com/blog/Posts/creating-date-table-power-bi

https://www.sqlbi.com/articles/creating-a-simple-date-table-in-dax/

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors