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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
LadyCat
Frequent Visitor

Calculating Total Value Based on Last Day of the Year or Latest Data Available

Hi, 

I need help with the following: I have data that looks like this - 

 

Date of Purchase    Product       Value

Dec 31, 2022           A

Jan 31, 2023            A

Feb 28, 2023           A

Dec 31, 2022           B

Jan 31, 2023            B

Dec 31, 2022           C

Dec 31, 2022           D

Dec 31, 2022           E

Jan 31, 2023            E

Feb 28, 2023           E

 

I need to create a report (with a measure?) that will return two things:

- The total value for products A, B, C, D, E on Dec 31, 2022

- The latest total available value for all products, so for the above that would be the following -

Feb 28, 2023           A 

Jan 31, 2023            B

Dec 31, 2022           C

Dec 31, 2022           D

Feb 28, 2023          E

 

Is there any way to do this without writing complicated DAX? I am fairly new to Power BI.

 

Thank you! 

 

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

Hi @LadyCat,

#1, You can try to use the following measure formula to summary values based on specific date.

 

Total for the last day of previous year=
VAR _lastdate =
    MAXX ( ALLSELECTED ( table ), [Date] )
RETURN
    CALCULATE (
        SUM ( table[value] ),
        FILTER (
            ALLSELECTED ( table ),
            [Date]
                = DATE ( YEAR ( _lastdate ) - 1, 12, 31 )
        )
    )

 

#2, I think you can use measure filter to filter visual records.

For detail operation steps, you can write a measure formula to get the last date based on category and compare with current date to return flag. Then you can use it on visual level filter to filter records.

 

flag=
VAR currdate =
    MAX ( table[Date] )
VAR _lastDate =
    CALCULATE (
        MAX ( table[Date] ),
        ALLSELECTED ( table ),
        VALUES ( table[Product] )
    )
RETURN
    IF ( currdate = _lastDate, "Y", "N" )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

Ceate a Calendar Table with a relationship (Many to One and Single) from the Date column of the Data Table to the Date column of the Calendar Table.  To your visual, drag Product from the Data Table.  Write these measures

Total = sum(Data[Value])

Total as on Dec 31 = calculate([Total],datesbetween(calendar[Date],date(2022,12,31),date(2022,12,31)))

Last date = max(Data[Date of Purchase])

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
v-shex-msft
Community Support
Community Support

Hi @LadyCat,

#1, You can try to use the following measure formula to summary values based on specific date.

 

Total for the last day of previous year=
VAR _lastdate =
    MAXX ( ALLSELECTED ( table ), [Date] )
RETURN
    CALCULATE (
        SUM ( table[value] ),
        FILTER (
            ALLSELECTED ( table ),
            [Date]
                = DATE ( YEAR ( _lastdate ) - 1, 12, 31 )
        )
    )

 

#2, I think you can use measure filter to filter visual records.

For detail operation steps, you can write a measure formula to get the last date based on category and compare with current date to return flag. Then you can use it on visual level filter to filter records.

 

flag=
VAR currdate =
    MAX ( table[Date] )
VAR _lastDate =
    CALCULATE (
        MAX ( table[Date] ),
        ALLSELECTED ( table ),
        VALUES ( table[Product] )
    )
RETURN
    IF ( currdate = _lastDate, "Y", "N" )

 

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.