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
PhMeDie
Helper I
Helper I

YTD Logic and filtering dates

Hi,

 

I need your help on below.

 

I have two tables, a date table and fact table.

 

I'd like to implement a simple (custom) YTD logic to sum up YTD sales.

 

See below formula.

 

Sales YTD = CALCULATE (
sum('Table'[Sales Quantity]),
FILTER (
Calendar_day,
AND (
Calendar_day[Calendar_day.Commercial Year]
= MAXX (
FILTER ( Calendar_day, Calendar_day[Calendar_day.Calendar Date] = Today() ),
Calendar_day[Calendar_day.Commercial Year]
), Calendar_day[Calendar_day.Commercial Year_Week]
<= MAXX (
FILTER ( Calendar_day, Calendar_day[Calendar_day.Calendar Date] = Today() ),
Calendar_day[Calendar_day.Commercial Year_Week]
)
)
)
)

 

The formula is giving me the right results, but then when I try for example to drag in the calendar date to see details by date, the table remains blank.

 

What am I doing wrong?

 

I hope you can help.

 

Best,

 

P.

 

 

 

 

1 ACCEPTED SOLUTION

Hi,

 

thanks for your reply.

 

It almost worked. In the end the following code did the trick. I added another ALLSELECTED and then it worked. I cannot explain exactly why, but am happy 🙂

 

Best,

 

P

 

YTD =
CALCULATE (
    SELECTEDMEASURE (),
    ALLSELECTED ( Calendar_day ),
    FILTER (
        Calendar_day,
        AND (
            Calendar_day[Calendar_day.Commercial Year]
                CALCULATE (
                    MAX ( Calendar_day[Calendar_day.Commercial Year] ),
                    FILTER (
                        ALL ( Calendar_day ),
                        Calendar_day[Calendar_day.Calendar Date] = TODAY ()
                    )
                ),
            Calendar_day[Calendar_day.Commercial Year_Week]
                <= CALCULATE (
                    MAX ( Calendar_day[Calendar_day.Commercial Year_Week] ),
                    FILTER (
                        ALL ( Calendar_day ),
                        Calendar_day[Calendar_day.Calendar Date] = TODAY ()
                    )
                )
        )
    )
)

 

 

 

View solution in original post

2 REPLIES 2
v-lid-msft
Community Support
Community Support

Hi @PhMeDie ,

 

We can try to use the following measure to meet your requirement:

 

Sales YTD =
CALCULATE (
    SUM ( 'Table'[Sales Quantity] ),
    FILTER (
        Calendar_day,
        AND (
            Calendar_day[Calendar_day.Commercial Year]
                = CALCULATE (
                    MAX ( Calendar_day[Calendar_day.Commercial Year] ),
                    FILTER (
                        ALLSELECTED ( Calendar_day ),
                        Calendar_day[Calendar_day.Calendar Date] = TODAY ()
                    )
                ),
            Calendar_day[Calendar_day.Commercial Year_Week]
                <= CALCULATE (
                    MAX ( Calendar_day[Calendar_day.Commercial Year_Week] ),
                    FILTER (
                        ALLSELECTED ( Calendar_day ),
                        Calendar_day[Calendar_day.Calendar Date] = TODAY ()
                    )
                )
        )
    )
)


If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.


Best regards,

 

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

Hi,

 

thanks for your reply.

 

It almost worked. In the end the following code did the trick. I added another ALLSELECTED and then it worked. I cannot explain exactly why, but am happy 🙂

 

Best,

 

P

 

YTD =
CALCULATE (
    SELECTEDMEASURE (),
    ALLSELECTED ( Calendar_day ),
    FILTER (
        Calendar_day,
        AND (
            Calendar_day[Calendar_day.Commercial Year]
                CALCULATE (
                    MAX ( Calendar_day[Calendar_day.Commercial Year] ),
                    FILTER (
                        ALL ( Calendar_day ),
                        Calendar_day[Calendar_day.Calendar Date] = TODAY ()
                    )
                ),
            Calendar_day[Calendar_day.Commercial Year_Week]
                <= CALCULATE (
                    MAX ( Calendar_day[Calendar_day.Commercial Year_Week] ),
                    FILTER (
                        ALL ( Calendar_day ),
                        Calendar_day[Calendar_day.Calendar Date] = TODAY ()
                    )
                )
        )
    )
)

 

 

 

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.