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
Anonymous
Not applicable

Max date sales per product

i am trying to calculate total sales by max date and product. So when the date filter changes the value should shift to the new max date this needs to be done in a measure but when i currently use the following i get the correct number but whne put in a tbale with the products its the grand total of sales duplicated for each product

 

CALCULATE(SUM('table1'[value]),ALLEXCEPT('table1','table1'[product]),FILTER( ALL('table1'), 'table1'[Date] = Max('table1'[Date])))

1 ACCEPTED SOLUTION
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create measure

Capture7.JPG

Measure =
VAR maxdate =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[product] = MAX ( 'Table'[product] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[product] = MAX ( 'Table'[product] )
                && 'Table'[date] = maxdate
        )
    )

 

Best Regards
Maggie
Community Support Team _ Maggie Li
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

5 REPLIES 5
v-juanli-msft
Community Support
Community Support

Hi @Anonymous 

Create measure

Capture7.JPG

Measure =
VAR maxdate =
    CALCULATE (
        MAX ( 'Table'[date] ),
        FILTER ( ALLSELECTED ( 'Table' ), 'Table'[product] = MAX ( 'Table'[product] ) )
    )
RETURN
    CALCULATE (
        SUM ( 'Table'[sales] ),
        FILTER (
            ALLSELECTED ( 'Table' ),
            'Table'[product] = MAX ( 'Table'[product] )
                && 'Table'[date] = maxdate
        )
    )

 

Best Regards
Maggie
Community Support Team _ Maggie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

amitchandak
Super User
Super User

@Anonymous , Try like

sumx(values(Table[product]),lastnonblankvalue(Table[sales date],sum(Table[sales])))

ryan_mayu
Super User
Super User

@Anonymous 

Please share the sample data.

 

I think if you use date filter, you don't need to calculate the maxdate. The value will change by changing the date filter.

 

CALCULATE(SUM('table1'[value]),ALLEXCEPT('table1','table1'[product]))

 

 

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Anonymous
Not applicable

@ryan_mayu  thank you but i need to as i only want the sum of the latest date i dont want the sum up to latest date

@Anonymous 

 

I am still not very clear about your scenario.

 

1.PNG

Show the latest date value by selection.

Measure = 
VAR maxdate=max('Table'[date])
return CALCULATE(sum('Table'[value]),'Table'[date]=maxdate)

2.PNG

 

Always show the latest date's value

Measure = 
VAR maxdate=CALCULATE(max('Table'[date]),all('Table'))
return CALCULATE(sum('Table'[value]),'Table'[date]=maxdate)

3.PNG

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.