Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.
Hi all!
I am new to PowerBi, so I need som help...
I need to create a measure from table called "Bokningar", for distinctcount of the number of weeks where column Malltyp is "Vara Pris" within a rolling 8-week period. I need it for indicating how many weeks out of the last 8 weeks had bookings with Malltyp as "Vara Pris". I need to see the result for each week.
The table has a date column for each row, so it should be based on that date. I tried several DAX measures to create the abovementioned calculation but I always get the wrong numbers.. Weekly(Vecka) results are either ones (1) or unrealistic numbers like 9 and 10. All the columns are properly formated with the right type of data type.
I tried following DAX:
Hi @Emink
I believe that it all depends on the current start and end weeks you have set in 'Date'[Week]. So if you have a start date and end date of each starting week, then there is potential to get up to 9 weeks (guaranteed). The 10 weeks, however, I'm not sure.
Can you copy / paste your Date table with the Week number, start and end?
Thanks heaps,
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Hi again @TheoC ,
I can share a pbx file with you and hopefullt it will bring more clarity.
https://drive.google.com/file/d/1RjP-ZisoxC3-H-YQZEuVF6A-pW8XNBxJ/view?usp=drive_link
Maybe it is worth to mention that I live in Sweden, and somehow date formats might get messed up (not sure, just a heads up).
Thank you so much for trying to help!
Looking forward your response.
/Emin
Hi @Emink
Can you please try the following:
RollingCount_VaraPris_8Weeks =
VAR CurrentDate = MAX ( Bokningar[Skapad] )
RETURN
CALCULATE (
DISTINCTCOUNT ( Bokningar[Vecka] ) ,
FILTER (
ALL ( 'Bokningar' ) ,
Bokningar[Skapad] <= CurrentDate &&
Bokningar[Skapad] > CurrentDate - 56 &&
Bokningar[Malltyp] = "Vara Pris"
)
)
The measure calculates the MAX date for context, then the distinct count of weeks, and the FILTER looks at ALL the rows in the 'Bokningar' table and filters accordingly. The 56 is just 8 weeks x 7 days so you can amend as needed.
Hope this helps! 🙂
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Hi @TheoC ,
thanks a lot for the response!
Please take a look at the screenshot below, i encounter the same problem when I am usiong my DAX...
I used your formula and here is how it looks like on the weekly basis:
It can't possibly be 10 discinct weeks wihtin a period of 8...
Hi @Emink
The issue is that the start and end of what constitutes a week is determined by the Date[Week] table and column. Therefore, the first date that is used for to calculate the distinct count of weeks using Bokningar[Vecka] will be different to the first date of the week based on Date[Week]. Therefore, it is very likely you will get 9 weeks counted frequently.
If you are using the TODAY() - 56, then there can theoretically be 57 days which has the potential to extend to 10 distinct weeks. For example, if Date[Week] starts 1 January 2024 to 7 January 2024, and Bokningar[Vecka] starts on 7 January 2024 and ends 56 days (instead of 55 days) later, then the 8 weeks will finish on 4 March 2024. As per below, the start period of 7 January 2024 is part of Date[Week] #1. The end date of 4 March 2024 is part of Date[Week] #10. Therefore, 10 distinct weeks is correct if you are using 56 + 1 days.
Let me know if this makes sense.
Thanks heaps,
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Hi Theo,
Thanks a lot for the explanation, it makes sense. So what would be the solution here? Reformating the start and end of the weeks? Besides the issue with 9s and 10s, the table in PowerBI displays wrong values for each week. For instance take Butik 244 for week 20 and 21 in 2024: the table displays "5" for each week which is completely wrong if you look into the Excel file that I attached here(the source of data):
According to the data from excel there should only be displayed 1 for week 21. I filtered the excel file so you could see it easily.
Thanks and looking forward to your explanation.
/Emin
Hi Theo,
Thanks a lot for the explanation, it makes sense. So what would be the solution here? Reformating the start and end of the weeks? Besides the issue with 9s and 10s, the table in PowerBI displays wrong values for each week. For instance take Butik 244 for week 20 and 21 in 2024: the table displays "5" for each week which is completely wrong if you look into the Excel file that I attached here(the source of data):
According to the data from excel there should only be displayed 1 for week 21. I filtered the excel file so you could see it easily.
Thanks and looking forward to your explanation.
/Emin
Hi @Emink
I've tried to access the file and also the spreadsheet but have not had any luck.
Are you able to provide me with an XLSX file or PBIX that I can download or access to assist?
Thanks heaps.
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias
Hi @TheoC
please use the link I attached. It will open in google drive(sheets), but use the download option and select (.xlsx) format. The file should be available to anyone with the link.
Hi @Emink
I also need the PBIX file. Unfortunately, I could not access it?
Thank you.
Theo
If I have posted a response that resolves your question, please accept it as a solution to formally close the post.
Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!
Want to connect?www.linkedin.com/in/theoconias