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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

How to produce a snapshot table using Power BI DAX measure

My intention is to populate days of the month to simulate a data warehouse periodic snapshot table using DAX measures. My goal is to show non-additive values for the quantity as shown below:

HelioD_1-1604733834552.png

However after applying the measure I end up with:

HelioD_2-1604733880785.png

There are two transactions. One on day 2 and the other on day 4. Instead of calculating a running total I want to show the latest Qty in the Snapshot column for the days which have no transactions. So, day 4 should show 4 instead of summing up day 3 and day 4 which gives me 6.

 

This is the measure I'm using:

 

Quantity =
CALCULATE(
      SUM('Inventory'[Quantity]),
      FILTER(
              ALL ( 'Date'[Date] ),
              'Date'[Date] <= MAX( 'Date'[Date] )
       )
)

 

1 ACCEPTED SOLUTION
daxer-almighty
Solution Sage
Solution Sage

In all earnest, such calculations should be performed in Power Query, especially on big fact tables. Doing this through DAX is not only slow. It's highly inefficient because of poor compression.

View solution in original post

5 REPLIES 5
daxer-almighty
Solution Sage
Solution Sage

In all earnest, such calculations should be performed in Power Query, especially on big fact tables. Doing this through DAX is not only slow. It's highly inefficient because of poor compression.

Anonymous
Not applicable

You are absolutely right. Just with sample data already it doesn't perform well. I will try the Power Query path. Would you have a reference of this being done using Power Query?

DataInsights
Super User
Super User

@Anonymous,

 

Try this measure:

 

Snapshot = 
VAR vCurrentDay =
    MAX ( SnapshotTest[Day] )
VAR vMaxDayWithQty =
    CALCULATE (
        MAX ( SnapshotTest[Day] ),
        ALL ( SnapshotTest ),
        SnapshotTest[Day] <= vCurrentDay,
        NOT ISBLANK ( SnapshotTest[Qty] )
    )
VAR vResult =
    CALCULATE (
        SUM ( SnapshotTest[Qty] ),
        ALL ( SnapshotTest ),
        SnapshotTest[Day] = vMaxDayWithQty
    )
RETURN
    IF ( ISBLANK ( vResult ), 0, vResult )

 

DataInsights_0-1604764549966.png

 





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

Proud to be a Super User!




Anonymous
Not applicable

I tried you're solution using my tables but it didn't work. I'm using a marked date table and hopefully that still can work with your recommended solution. I only had blanks for the Snapshot column:

Quantity Snapshot =
VAR vCurrentDay =
MAX ( 'Date'[Day] )
VAR vMaxDayWithQty =
CALCULATE (
MAX ( 'Date'[Day] ),
ALL ( 'Date' ),
'Date'[Day] <= vCurrentDay,
NOT ISBLANK ( 'Inventory'[Quantity] )
)
VAR vResult =
CALCULATE (
SUM ( 'Inventory'[Quantity] ),
ALL ( 'Inventory' ),
'Date'[Day] = vMaxDayWithQty
)
RETURN
IF ( ISBLANK ( vResult ), 0, vResult )

Anonymous
Not applicable

Much appreciated for your reply. I have a couple of questions:
1. Is SnapshotTest a Date table? In my scenario I have a Date table marked as date table in Power BI and an Inventory table.
2. It is also possible to have multiple entries per day. In this case I would be interested only in the last entry for the day. The inventory table has another column called RecordedDate which shows data and time. Rather than summing up how would you select the Qty related to the latest transaction for the day?

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.