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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
PowerBITestingG
Resolver I
Resolver I

Get sum of quantity for last selected date

I have a bar chart with date and a sum of quantity. Next to it I have a table with Countries and "Dynamic" sum of quantity.

The idea is that when people click on the dates in the bar chart, the table next to it shows those values, and if nothing is selected then it defaults to showing the last date data.

Dynamic sum of quantity
VAR maxx2 =
    MAXX (
        FILTER (
            ALLSELECTED (fact),
            fact[snapshotdate]
        ),
        fact[snapshotdate])
VAR __Result=
    CALCULATE ( sum(quantity),  fact[snapshotdate] = maxx2 )
return __Result

This produces the desired result except when the following happens:

- If today a country doesnt have any rows on the table and someone uses a filter to show only that country then the measure returns the last date with data (previous day) which creates confusion because people would expect the table to show nothing in that case.

 

Any ideas on how to fix it?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @PowerBITestingG ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Dynamic sum of quantity = 
VAR _country = SELECTEDVALUE ( 'fact'[country] )
VAR maxx2 =
    MAXX (
        FILTER (
            ALLSELECTED ( 'fact' ),
            'fact'[country] = _country
        ),
        'fact'[snapshotdate]
    )
VAR __Result =
    CALCULATE (
        SUM ( 'fact'[quantity] ),
        FILTER (
            ALLSELECTED ( 'fact' ),
            'fact'[country] = _country
                && 'fact'[snapshotdate] = maxx2
        )
    )
RETURN
    IF ( ISFILTERED ( 'fact'[snapshotdate] ), SUM ( 'fact'[quantity] ), __Result )

vyiruanmsft_1-1699337980804.png

If the above one can't help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @PowerBITestingG ,

I created a sample pbix file(see the attachment), please check if that is what you want.

Dynamic sum of quantity = 
VAR _country = SELECTEDVALUE ( 'fact'[country] )
VAR maxx2 =
    MAXX (
        FILTER (
            ALLSELECTED ( 'fact' ),
            'fact'[country] = _country
        ),
        'fact'[snapshotdate]
    )
VAR __Result =
    CALCULATE (
        SUM ( 'fact'[quantity] ),
        FILTER (
            ALLSELECTED ( 'fact' ),
            'fact'[country] = _country
                && 'fact'[snapshotdate] = maxx2
        )
    )
RETURN
    IF ( ISFILTERED ( 'fact'[snapshotdate] ), SUM ( 'fact'[quantity] ), __Result )

vyiruanmsft_1-1699337980804.png

If the above one can't help you get the expected result, please provide some raw data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

Find out what's new and trending in the Fabric community.

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.