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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
Fier
Regular Visitor

How to get the latest data for a field at a point in time

I am having trouble with interpreting an audit trail.  The ultimate goal is to have a time slicer that allows the report user to see what the data looked like at any point in the past. Because I'm struggling, I'm taking a staged approach:

  • reproduce the live report by referring to the last record of every category, but from the audit trail (done)
  • reproduce the report at a fixed point in time (trouble with this)
  • create a dynamic timeline on one page (future ambition, a different issue to solve with 'calculate' and 'allexcept') 

 

The real table has dozens of columns, but I hope that the information here will be adequate. I started with creating a new table with a summarize command. Then I improved the code a bit to be more accurate and flexible, and used CalculateTable:

 

2022Q2 = 
VAR _filter = Filter(View, TRUE())
//VAR _filter = Filter(View, value(View[Date]) < Value(DATE(2022,07,01)))
RETURN
CalculateTable(View, 
    _filter, 
    filter(View, 
        View[Version] = MaxX(
           Filter(_filter, (View[Key] = Earlier(View[Key]))), 
           View[Version]
        )    
    )
)

 

Because the date is in the future, I can interchange the commented code with the VAR line and get the same, expected, result. 

Fier_0-1655460381449.png

 

 

When I change the date to something in the past, I am dropping records incorrectly.

 

2021Q4 = 
VAR _filter = filter(View, value(View[Date]) < Value(DATE(2022,01,01)))
RETURN
CalculateTable(View, 
    _filter,
    filter(View, 
       View[Version] = MaxX(
           filter(_filter, (View[Key] = earlier(View[Key]))), 
           View[Version]
        )    
    )
)

 

Fier_1-1655460408729.png

The expected number should be over 1000 records. This count of 75 shows the records that were not updated this year - the records which have a max version before the filter date.

 

I would appreciate assistance in fixing the formula for creating tables at a fixed point in time.  

 

 

1 ACCEPTED SOLUTION
Fier
Regular Visitor

I just solved my own problem while writing the question. 

My original code was copied with the corrected filter before I saw that the result was right:

 

2021Q4 = 
VAR _filter = filter(View, value(View[Date]) < Value(DATE(2022,01,01)))
RETURN
CalculateTable(View, 
    _filter,
    filter(View, 
       View[Version] = MaxX(
           filter(View, (View[Key] = earlier(View[Key]))), 
           View[Version]
        )    
    )
)

 

This was the code used to get the wrong result - notice the filter in MAXX

(apologies if anybody was looking at this in the time it took me to see that it was solved!)

View solution in original post

1 REPLY 1
Fier
Regular Visitor

I just solved my own problem while writing the question. 

My original code was copied with the corrected filter before I saw that the result was right:

 

2021Q4 = 
VAR _filter = filter(View, value(View[Date]) < Value(DATE(2022,01,01)))
RETURN
CalculateTable(View, 
    _filter,
    filter(View, 
       View[Version] = MaxX(
           filter(View, (View[Key] = earlier(View[Key]))), 
           View[Version]
        )    
    )
)

 

This was the code used to get the wrong result - notice the filter in MAXX

(apologies if anybody was looking at this in the time it took me to see that it was solved!)

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.