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
Ram107568
Frequent Visitor

YTD is not calculating correct value when there is blank in one of the months

I am trying to calculate YTD. Now Cust A and Cust C has orders for both Jan and Feb. Cust B does not have orders for Feb Month. Now if I select Feb month in slicer, Cust B is not showing up. But as cumulative, I need to show 8 for Cust B even if I select Feb in slicer 

CustomerFirst_day_of_monthNo_of_ordersYTD
Cust A2023/01/0122
Cust A2023/02/0135
Cust B2023/01/0188
Cust C2023/01/0155
Cust C2023/02/0127

 

Below is the calculation I use.

 

YTD1 =
CALCULATE(
    [No_of_orders],
    DATESINPERIOD( Tbl[First_day_of_month] , MAX(Tbl[First_day_of_month]) , -12 ,MONTH)
 
Appreciate your help on this!
2 ACCEPTED SOLUTIONS
some_bih
Super User
Super User

Hi @Ram107568 for DATESINPERIOD, you will need Tbl to be your Calendar / Date table. Try to chenge it and see results . (Date / Calendar table must always start on January 1 and end on December 31, including all the days in this range so you should be fine with your issue for blank months).

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





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

Proud to be a Super User!






View solution in original post

v-rongtiep-msft
Community Support
Community Support

Hi @Ram107568 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create a table first.

calendar = CALENDAR(DATE(2023,1,1),DATE(2023,12,31))

 Then create a measure.

Measure =
CALCULATE (
    SUM ( 'Table'[No_of_orders] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[First_day_of_month] <= SELECTEDVALUE ( 'calendar'[Date] )
            && 'Table'[Customer] = SELECTEDVALUE ( 'Table'[Customer] )
    )
)

 

Finally put the 'calendar'[date] into the slicer.

vrongtiepmsft_0-1689126538968.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

View solution in original post

5 REPLIES 5
v-rongtiep-msft
Community Support
Community Support

Hi @Ram107568 ,

I have created a simple sample, please refer to my pbix file to see if it helps you.

Create a table first.

calendar = CALENDAR(DATE(2023,1,1),DATE(2023,12,31))

 Then create a measure.

Measure =
CALCULATE (
    SUM ( 'Table'[No_of_orders] ),
    FILTER (
        ALL ( 'Table' ),
        'Table'[First_day_of_month] <= SELECTEDVALUE ( 'calendar'[Date] )
            && 'Table'[Customer] = SELECTEDVALUE ( 'Table'[Customer] )
    )
)

 

Finally put the 'calendar'[date] into the slicer.

vrongtiepmsft_0-1689126538968.png

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Thanks @v-rongtiep-msft for recreating the sample table and helping me with the issue. This solved my problem.

some_bih
Super User
Super User

Hi @Ram107568 for DATESINPERIOD, you will need Tbl to be your Calendar / Date table. Try to chenge it and see results . (Date / Calendar table must always start on January 1 and end on December 31, including all the days in this range so you should be fine with your issue for blank months).

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





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

Proud to be a Super User!






Hello @v-rongtiep-msft , what if I had to add date also to the table along with customer and measure. YTD isn't working as expecetd when I add date column to it. The below result is what i get.

Ram107568_0-1689532922910.png

 

For instance, if I select 02/01/2023 in slicer, the result should as follows. Without dates,it's working awesome. If I try to introduce dates, then the trouble starts.

 

CustomerFirst_day_of_monthNo_of_ordersYTD
Cust A2023/01/0122
Cust A2023/02/0135
Cust B2023/01/0188
Cust C2023/01/0155
Cust C2023/02/0127

 

 

I had to export this data to excel which acts as source for another snapshot report. So I would be needing date to it

 

Thanks

@some_bih Thanks  for the suggestions. It worked with the calendar table

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.