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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
NimaiAhluwalia
Responsive Resident
Responsive Resident

YTD custom logic

How would you write a dax code in power bi when you have a date table and it is connected to you sales fact table with the date column and you want to create a bar chart which shows the data of YTD sales as of 08/01/2025 and when we move back on the graph it will shows me the sales of YTD till 08/12/2024 and if we move more backwards than 08/11/2024, each data point in the graph would be the YTD till the current date which is 8th Jan but the month and the year would be different. 

 

and if date is 09/01/2025 than all the past pointers will be 09/12/2024 , 09/11/2024, when i scroll my mouse on the graph.
and if date is 10/01/2025 than all the past pointers will be 10/12/2024 , 10/11/2024, when i scroll my mouse on the graph.

and if date is 22/01/2025 than all the past pointers will be 22/12/2024 , 22/11/2024, when i scroll my mouse on the graph.

exmaple 1

NimaiAhluwalia_0-1736353152624.png

example 2

NimaiAhluwalia_1-1736353223571.png

example 3

 

NimaiAhluwalia_2-1736353293562.png

 

 

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

Hi @NimaiAhluwalia ,
According to your description, you can use tooltip to do this, here are the steps to implement it.
First, create a calculated column to calculate the cumulative value.

Cumulative Sales = 
VAR _current = 'Fact Table'[Date]
RETURN
CALCULATE(
    SUM('Fact Table'[Sales Amount]),
    FILTER(
        'Fact Table',
        'Fact Table'[Date] <= _current
    )
)


Then, create a filter table that is not related to any other table.

Slicer Table = VALUES('Fact Table'[Date])


Next, create measures

DateKey = 
VAR _selectedDate = MAX('Slicer Table'[Date])
VAR _day = DAY(_selectedDate)
VAR _currentYear = Year(SELECTEDVALUE('Fact Table'[Date]))
VAR _currentMonth = MONTH(SELECTEDVALUE('Fact Table'[Date]))
VAR _sameDateLastMonth = DATE(_currentYear,_currentMonth,_day)
RETURN
_sameDateLastMonth
IsBeforeSelectedDate = 
IF(
    SELECTEDVALUE('Fact Table'[Date]) <= MAX('Slicer Table'[Date]),
    1,
    0
)IsBeforeSelectedDate = 
IF(
    SELECTEDVALUE('Fact Table'[Date]) <= MAX('Slicer Table'[Date]),
    1,
    0
)

 

Then you need to create a tooltip page

vheqmsft_0-1736404782698.png

vheqmsft_1-1736404800481.png

On the final page, you need to configure filters for the visualization

vheqmsft_2-1736404874160.png

and enable tooltip

vheqmsft_3-1736404913883.png

vheqmsft_4-1736404913934.png

Final output

vheqmsft_5-1736404930069.png

vheqmsft_7-1736404945514.png

Create report tooltip pages in Power BI - Power BI | Microsoft Learn

 

Best regards,
Albert He


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

1 REPLY 1
v-heq-msft
Community Support
Community Support

Hi @NimaiAhluwalia ,
According to your description, you can use tooltip to do this, here are the steps to implement it.
First, create a calculated column to calculate the cumulative value.

Cumulative Sales = 
VAR _current = 'Fact Table'[Date]
RETURN
CALCULATE(
    SUM('Fact Table'[Sales Amount]),
    FILTER(
        'Fact Table',
        'Fact Table'[Date] <= _current
    )
)


Then, create a filter table that is not related to any other table.

Slicer Table = VALUES('Fact Table'[Date])


Next, create measures

DateKey = 
VAR _selectedDate = MAX('Slicer Table'[Date])
VAR _day = DAY(_selectedDate)
VAR _currentYear = Year(SELECTEDVALUE('Fact Table'[Date]))
VAR _currentMonth = MONTH(SELECTEDVALUE('Fact Table'[Date]))
VAR _sameDateLastMonth = DATE(_currentYear,_currentMonth,_day)
RETURN
_sameDateLastMonth
IsBeforeSelectedDate = 
IF(
    SELECTEDVALUE('Fact Table'[Date]) <= MAX('Slicer Table'[Date]),
    1,
    0
)IsBeforeSelectedDate = 
IF(
    SELECTEDVALUE('Fact Table'[Date]) <= MAX('Slicer Table'[Date]),
    1,
    0
)

 

Then you need to create a tooltip page

vheqmsft_0-1736404782698.png

vheqmsft_1-1736404800481.png

On the final page, you need to configure filters for the visualization

vheqmsft_2-1736404874160.png

and enable tooltip

vheqmsft_3-1736404913883.png

vheqmsft_4-1736404913934.png

Final output

vheqmsft_5-1736404930069.png

vheqmsft_7-1736404945514.png

Create report tooltip pages in Power BI - Power BI | Microsoft Learn

 

Best regards,
Albert He


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

 

 

 

 

 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.