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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
krishna_1811
Frequent Visitor

Running Total with three years

I have a sales table with the booking amount(Int Format), fiscal quarter, and fiscal week in text format. they have values , fiscal quarter from 2022Q1 TO 2025Q4 and each quarter has 13 weeks values such as w01,w02,till w13. I have a slicer with the fiscal quarter. fiscal quarter 2025q4 has only 4 weeks of data rest of the quarters have all 13 weeks of data, when I select 2025q4 it should show 4 weeks of data or till it has but the rest of quarters 2024q4, 2023q4 calculated dynamically with slicer selection 2025q4 should display all week 13 data, I need to calculate cumulative booking amount and show three lines on line chart, one for selected quarter, rest two line s previous year same quarter, previous to previous year same quarter.

 

I am using the below Dax but it is showing 4 weeks of data for all means 2025q4 is showing 4 weeks of data, and other 2024q4,2023q4 also showing 4 weeks of data which is incorrect they should show 13 weeks of data.  please support me

 

 

previous year quarter =

var selected_quarter= SELECTEDVALUE(DNM_DRILL_THROUGH[FISCAL_QTR])

var curren_year = int(left(selected_quarter,4))

var current_qtr = right(selected_quarter,2)

var pqtr=(current_year-1)&current_qtr

var max_week = int(right(CALCULATE(MAX(DNM_DRILL_THROUGH[FISCAL_WEEK_NUMBER_D]),DNM_DRILL_THROUGH[FISCAL_QTR]=pqtr),2)) RETURN

CALCULATE([Filterbookingamount],

ALLSELECTED (DNM_DRILL_THROUGH[fiscal_qtr]),

DNM_DRILL_THROUGH[FISCAL_QTR]=pqtr,

int(right(DNM_DRILL_THROUGH[FISCAL_WEEK_NUMBER_D],2))<=max_week)

1 ACCEPTED SOLUTION

Hi @krishna_1811,

Apologize for the delayed response. After thoroughly reviewing the details you provided, I reproduced the scenario again, and it worked on my end. I used it as sample data and successfully implemented it.

outcome:

vkpolojumsft_0-1749199100067.png

 


I am also including .pbix file for your better understanding, please have a look into it:

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

View solution in original post

9 REPLIES 9
v-kpoloju-msft
Community Support
Community Support

Hi @krishna_1811,

Thank you for reaching out to the Microsoft fabric community forum. Thank you @Ray_Minds, and @rajendraongole1, for your inputs on this issue. After thoroughly reviewing the details you provided, I was able to reproduce the scenario, and it worked on my end. I have used it as sample data on my end and successfully implemented it.

Please try this measures I have tried with some sample data in my end, it worked fine:

Selected Quarter Cumulative Booking Amount:

CumulativeBookingAmount =

VAR SelectedQuarter = SELECTEDVALUE(SalesTable[Fiscal Quarter])

VAR MaxWeek = MAXX(FILTER(SalesTable, SalesTable[Fiscal Quarter] = SelectedQuarter), SalesTable[FiscalWeekNumber])

RETURN

CALCULATE(

    SUM(SalesTable[Booking Amount]),

    SalesTable[Fiscal Quarter] = SelectedQuarter,

    SalesTable[FiscalWeekNumber] <= MaxWeek

)


Previous Year Same Quarter Cumulative Booking Amount:

PY_CumulativeBookingAmount =

VAR SelectedQuarter = SELECTEDVALUE(SalesTable[Fiscal Quarter])

VAR CurrentYear = LEFT(SelectedQuarter, 4) * 1

VAR CurrentQtr = RIGHT(SelectedQuarter, 2)

VAR PrevQuarter = FORMAT(CurrentYear - 1, "0000") & CurrentQtr

RETURN

CALCULATE(

    SUM(SalesTable[Booking Amount]),

    SalesTable[Fiscal Quarter] = PrevQuarter

)

Previous to Previous Year Same Quarter Cumulative Booking Amount:

PPY_CumulativeBookingAmount =

VAR SelectedQuarter = SELECTEDVALUE(SalesTable[Fiscal Quarter])

VAR CurrentYear = LEFT(SelectedQuarter, 4) * 1

VAR CurrentQtr = RIGHT(SelectedQuarter, 2)

VAR PrevPrevQuarter = FORMAT(CurrentYear - 2, "0000") & CurrentQtr

RETURN

CALCULATE(

    SUM(SalesTable[Booking Amount]),

    SalesTable[Fiscal Quarter] = PrevPrevQuarter

)

 

vkpolojumsft_0-1742896430318.pngvkpolojumsft_1-1742896455091.pngvkpolojumsft_2-1742896486759.png

 


I am also including .pbix file for your better understanding, please have a look into it:


I hope this could resolve your issue, if you need any further assistance, feel free to reach out. If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

approach is good but when i selected 2025Q4 it is only showing current year data, it should show three lines in a single chart with 4 weeks data for 2025q4 and all 13 weeks dta for 2024q4,2023q4

Hi @krishna_1811,

Apologize for the delayed response. After thoroughly reviewing the details you provided, I reproduced the scenario again, and it worked on my end. I used it as sample data and successfully implemented it.

outcome:

vkpolojumsft_0-1749199100067.png

 


I am also including .pbix file for your better understanding, please have a look into it:

If this post helps, then please give us ‘Kudos’ and consider Accept it as a solution to help the other members find it more quickly.

Thank you for using Microsoft Community Forum.

Hi @krishna_1811,

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.
Thank you.

Hi @krishna_1811,

 

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you.

Hi @krishna_1811,


I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.


Thank you.

Hi @krishna_1811,


I hope this information is helpful. Please let me know if you have any further questions or if you'd like to discuss this further. If this answers your question, please Accept it as a solution and give it a 'Kudos' so others can find it easily.


Thank you.

Ray_Minds
Continued Contributor
Continued Contributor

Hi @krishna_1811 

Please use this DAX to get the correct answer 

Cumulative Booking Amount =

VAR selected_quarter = SELECTEDVALUE(DNM_DRILL_THROUGH[FISCAL_QTR])

VAR current_year = INT(LEFT(selected_quarter, 4))  -- Extracts the year

VAR current_qtr = RIGHT(selected_quarter, 2)       -- Extracts the quarter

 

-- Get previous and previous-to-previous year quarters

VAR pqtr = FORMAT(current_year - 1, "0000") & current_qtr

VAR ppqtr = FORMAT(current_year - 2, "0000") & current_qtr

 

-- Get max week available for the selected quarter

VAR max_week_selected =

    MAXX(

        FILTER(DNM_DRILL_THROUGH, DNM_DRILL_THROUGH[FISCAL_QTR] = selected_quarter),

        INT(RIGHT(DNM_DRILL_THROUGH[FISCAL_WEEK_NUMBER_D], 2))

    )

 

-- Compute Cumulative Booking Amount

RETURN

CALCULATE(

    [Filterbookingamount],  -- Use your booking amount measure

    DNM_DRILL_THROUGH[FISCAL_QTR] IN { selected_quarter, pqtr, ppqtr },

    IF(

        DNM_DRILL_THROUGH[FISCAL_QTR] = selected_quarter,

        INT(RIGHT(DNM_DRILL_THROUGH[FISCAL_WEEK_NUMBER_D], 2)) <= max_week_selected,

        TRUE()  -- Ensures previous quarters show all 13 weeks

    )

)




Best regards,
Ray Minds
http://www.rayminds.com
https://www.linkedin.com/company/rayminds/

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

rajendraongole1
Super User
Super User

Hi @krishna_1811  - can you change the logic for previous year as below:

 

PreviousYearQuarter =
VAR SelectedQuarter = SELECTEDVALUE(DNM_DRILL_THROUGH[FISCAL_QTR]) -- Selected quarter from slicer
VAR CurrentYear = INT(LEFT(SelectedQuarter,4)) -- Extract year
VAR CurrentQtr = RIGHT(SelectedQuarter,2) -- Extract Q1, Q2, etc.
VAR PrevYearQtr = FORMAT(CurrentYear - 1, "0000") & CurrentQtr -- Get previous year same quarter

-- Find max week number for selected quarter
VAR MaxWeekSelectedQtr =
MAXX(
FILTER(DNM_DRILL_THROUGH, DNM_DRILL_THROUGH[FISCAL_QTR] = SelectedQuarter),
INT(RIGHT(DNM_DRILL_THROUGH[FISCAL_WEEK_NUMBER_D], 2))
)

RETURN
CALCULATE(
[FilterBookingAmount], -- Your measure for Booking Amount
ALLSELECTED(DNM_DRILL_THROUGH[FISCAL_QTR]),
DNM_DRILL_THROUGH[FISCAL_QTR] = PrevYearQtr,

-- Ensure previous year always shows full 13 weeks, while selected quarter is restricted dynamically
IF(
SelectedQuarter = PrevYearQtr,
INT(RIGHT(DNM_DRILL_THROUGH[FISCAL_WEEK_NUMBER_D],2)) <= 13, -- Show full 13 weeks for previous year
INT(RIGHT(DNM_DRILL_THROUGH[FISCAL_WEEK_NUMBER_D],2)) <= MaxWeekSelectedQtr -- Restrict only selected quarter
)
)

 

Hope this helps. . please check





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

Proud to be a Super User!





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.