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
romoguy15
Helper IV
Helper IV

Dax total tickets last 4 fiscal weeks not including current week

Hello, 

 

I am trying to figure out a dax measure that gives me my total count of tickets based on the last 4 fiscal weeks not including the current fiscal week we are in. Below is my measure I am using my it is not correctly calculating. I have some sample data to share if anyone can assist.

 

https://1drv.ms/u/s!AqID1H0nHPOzhAsuNYCFESehpBTd?e=yiIFt1

 

Total Tickets(Past 4 Weeks) =
CALCULATE([Total Tickets],
FILTER('Calendar', 'Calendar'[FiscalWeek]<CALCULATE(MAX('Calendar'[FiscalWeek]),
FILTER('Calendar',[Date]=TODAY())) && 'Calendar'[FiscalWeek]>=CALCULATE(MAX('Calendar'[FiscalWeek]),
FILTER('Calendar',[Date]=TODAY()))-4))
2 ACCEPTED SOLUTIONS
Greg_Deckler
Super User
Super User

@romoguy15 I think a lot of this had to do with you using Page Filters instead of visual filters. For example, of course your "Total Tickets(Past 4 Weeks)" showed blank because you filtered out TODAY essentially. In any event, here is an improved formula that will ignore filters. You are going to have an issue though as you cycle years. I highly recommend a sequential fiscal week number to avoid this sort of thing or perhaps you have a different method of rolling over years. Here is the new formula and updated PBIX with filters corrected below sig. I only ever got the 121 figure when I used ALL in the formula and did not filter by year = YEAR(TODAY()) so I'm guessing that you had 4 tickets in 2020 in the same fiscal year.

Total Tickets(Past 4 Weeks) 2 = 
CALCULATE([Total Tickets],
    FILTER(ALL('Calendar'), 'Calendar'[Year] = YEAR(TODAY()) && 'Calendar'[FiscalWeek]<CALCULATE(MAX('Calendar'[FiscalWeek]),
            FILTER('Calendar',[Date]=TODAY())) && 'Calendar'[FiscalWeek]>=CALCULATE(MAX('Calendar'[FiscalWeek]),
                    FILTER('Calendar',[Date]=TODAY()))-4))

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

@romoguy15 I think you need to download and look at the PBIX file I attached as I fixed everything so that it returns 117, not 121. Perhaps I was unclear about that. There are numerous ways to get a sequential week number, here is a DAX way I came up with:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Sequential/m-p/380231#M116

 

Greg_Deckler_0-1626473252755.png

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

7 REPLIES 7
romoguy15
Helper IV
Helper IV

@Greg_Deckler  Dude that post for the seqential week column is awesome! This really helps me on so many other formulas that I could not solve for.

romoguy15
Helper IV
Helper IV

Hey @Greg_Deckler , I understand your mention of the page level filters, but even if I removed that and manually selected the fiscal weeks in the table, it still comes up blank. Unfortunately 121 is still not the right total.  Regarding the sequential weeks, are you referring to creating some sort of index for the calendar? I think I understand what you are asking. Essentially the fiscal weeks causes issues because any week could be in multiple years. So I did some digging on those 4 that total up to 121 and essentially those 4 fall within the 4 fiscal weeks of 20-23 but that is not good since it's last year. I really want to avoid this.

@romoguy15 I think you need to download and look at the PBIX file I attached as I fixed everything so that it returns 117, not 121. Perhaps I was unclear about that. There are numerous ways to get a sequential week number, here is a DAX way I came up with:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Sequential/m-p/380231#M116

 

Greg_Deckler_0-1626473252755.png

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler  Sorry about that. I completely read right over the download link. I do see the fix which is fantastic. I guess I did misunderstand if the new formula would avoid the issue I had prior? Is the sequential week number still need in this particular scenario? I know for sure I'll have many more instances of needing to go back to prior fiscal weeks and want to avoid suming up prior years.

@romoguy15 Should avoid the issues you had even with page filters because of the ALL.

 

That said, no, the fix does not include a sequential fiscal week number which makes things easier. There are ways to do it without it but it is a lot of checking what week you are in. It's not the end of the world but way more painful than setting up a sequential number most times.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

@Greg_Deckler Thanks for all the help. I added the seqential week column into my calendar and tested it in my old formula and it solved the issue. Thanks again. I will probably use your improved one to avoid page level filters so that's also great.

Greg_Deckler
Super User
Super User

@romoguy15 I think a lot of this had to do with you using Page Filters instead of visual filters. For example, of course your "Total Tickets(Past 4 Weeks)" showed blank because you filtered out TODAY essentially. In any event, here is an improved formula that will ignore filters. You are going to have an issue though as you cycle years. I highly recommend a sequential fiscal week number to avoid this sort of thing or perhaps you have a different method of rolling over years. Here is the new formula and updated PBIX with filters corrected below sig. I only ever got the 121 figure when I used ALL in the formula and did not filter by year = YEAR(TODAY()) so I'm guessing that you had 4 tickets in 2020 in the same fiscal year.

Total Tickets(Past 4 Weeks) 2 = 
CALCULATE([Total Tickets],
    FILTER(ALL('Calendar'), 'Calendar'[Year] = YEAR(TODAY()) && 'Calendar'[FiscalWeek]<CALCULATE(MAX('Calendar'[FiscalWeek]),
            FILTER('Calendar',[Date]=TODAY())) && 'Calendar'[FiscalWeek]>=CALCULATE(MAX('Calendar'[FiscalWeek]),
                    FILTER('Calendar',[Date]=TODAY()))-4))

 

 


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

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.

Top Solution Authors