Forum Discussion
How to setup KPI for previous week and previous 2 weeks
Hello,
I have the following table from Excel and imported into Power BI. The ISO week number is calculated from the Date. I would like to have a KPI card that dynamically shows the previous week total submissions against the previous 2 weeks submissions. So, we are currently in ISO week number 7 and the KPI visualization should show the total submissions in week 6 against week 5 (as reference). I don't know how to do this. Is this possible? Any help is much appreciated!
| Date | Week Number | Student Name | Submissions |
| 03/01/2022 | 1 | Lizui | 4 |
| 06/01/2022 | 1 | Laufenburg | 7 |
| 11/01/2022 | 2 | Tegalpapak | 8 |
| 12/01/2022 | 2 | Ar Rabiyah | 5 |
| 22/01/2022 | 3 | Bellegarde | 3 |
| 21/01/2022 | 3 | Gangarampur | 3 |
| 25/01/2022 | 4 | Luntas | 1 |
| 26/01/2022 | 4 | Frei Paulo | 6 |
| 26/01/2022 | 4 | Seedorf | 2 |
| 03/02/2022 | 5 | Bellegarde | 3 |
| 05/02/2022 | 5 | Gangarampur | 3 |
| 11/02/2022 | 6 | Luntas | 1 |
| 09/02/2022 | 6 | Cosamaloapan de Carpio | 7 |
| 15/02/2022 | 7 | Zagrodno | 9 |
Hi Anonymous
You can use these measures.
Previous Week Total = var _weekEnd = TODAY() - WEEKDAY(TODAY(),2) var _weekStart = _weekEnd - 6 return CALCULATE(SUM('Table'[Submissions]),ALL('Table'),'Table'[Date]>=_weekStart,'Table'[Date]<=_weekEnd)Previous 2 Week Total = var _weekEnd = TODAY() - WEEKDAY(TODAY(),2) - 7 var _weekStart = _weekEnd - 6 - 7 return CALCULATE(SUM('Table'[Submissions]),ALL('Table'),'Table'[Date]>=_weekStart,'Table'[Date]<=_weekEnd)I don't use the week number column. I calculate the week start date and week end date based on today's date directly in measures and use them to filter the table. My week is from Monday to Sunday. You can adjust the number substracted if needed.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
5 Replies
- v-jingzhang
Community Support
Hi Anonymous
You can use these measures.
Previous Week Total = var _weekEnd = TODAY() - WEEKDAY(TODAY(),2) var _weekStart = _weekEnd - 6 return CALCULATE(SUM('Table'[Submissions]),ALL('Table'),'Table'[Date]>=_weekStart,'Table'[Date]<=_weekEnd)Previous 2 Week Total = var _weekEnd = TODAY() - WEEKDAY(TODAY(),2) - 7 var _weekStart = _weekEnd - 6 - 7 return CALCULATE(SUM('Table'[Submissions]),ALL('Table'),'Table'[Date]>=_weekStart,'Table'[Date]<=_weekEnd)I don't use the week number column. I calculate the week start date and week end date based on today's date directly in measures and use them to filter the table. My week is from Monday to Sunday. You can adjust the number substracted if needed.
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.- AnonymousNot applicable
v-jingzhang Thanks a lot for the support! I have a follow-up question - if i add an extra column called "Feedback", how to sum and group the number values with the "Submissions" column, according to the dates? That is, i want to show the total number of submissions and feedback in the previous week and previous 2 weeks. Is it possible? Any help is much appreciated!
Date Week Number Student Name Submissions Feedback 03/01/2022 1 Lizui 4 2 06/01/2022 1 Laufenburg 7 5 11/01/2022 2 Tegalpapak 8 8 12/01/2022 2 Ar Rabiyah 5 6 22/01/2022 3 Bellegarde 3 8 21/01/2022 3 Gangarampur 3 3 25/01/2022 4 Luntas 1 1 26/01/2022 4 Frei Paulo 6 5 26/01/2022 4 Seedorf 2 1 03/02/2022 5 Bellegarde 3 4 05/02/2022 5 Gangarampur 3 7 11/02/2022 6 Luntas 1 2 09/02/2022 6 Cosamaloapan de Carpio 7 3 15/02/2022 7 Zagrodno 9 9 - v-jingzhang
Community Support
Hi Anonymous
Sorry it's not clear to me. Can you show the new expected result based on your sample data? I guess you may want something like below?
Previous Week Total = var _weekEnd = TODAY() - WEEKDAY(TODAY(),2) var _weekStart = _weekEnd - 6 return CALCULATE(SUM('Table'[Submissions])+SUM('Table'[Feedback]),ALL('Table'),'Table'[Date]>=_weekStart,'Table'[Date]<=_weekEnd)Previous 2 Week Total = var _weekEnd = TODAY() - WEEKDAY(TODAY(),2) - 7 var _weekStart = _weekEnd - 6 - 7 return CALCULATE(SUM('Table'[Submissions])+SUM('Table'[Feedback]),ALL('Table'),'Table'[Date]>=_weekStart,'Table'[Date]<=_weekEnd)Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
- mh2587
Super User
Last 2 Week Submission = CALCULATE(SUM(Table[Submissions]),DATEADD('Table'[Date],-14,DAY))- AnonymousNot applicable
Hi mh2587 Thanks for your reply! But the problem is that it is 14 days behind, am i correct? I want to isolate each week completely, the whole of week 6 against week 5 (target) and it should not matter which day of the current week (number 7) that i refresh this data to recalculate. So, i think maybe it is more practical to consider by week number instead? So, here is the simplified table below:
Week Number Student Name Submissions 1 Lizui 4 1 Laufenburg 7 2 Tegalpapak 8 2 Ar Rabiyah 5 3 Bellegarde 3 3 Gangarampur 3 4 Luntas 1 4 Frei Paulo 6 4 Seedorf 2 5 Bellegarde 3 5 Gangarampur 3 6 Luntas 1 6 Cosamaloapan de Carpio 7 7 Zagrodno 9
The problem is that if today is wednesday, then it will consider the last 14 days so not the last 2 weeks entirely, since it will only consider part of week 5 and then also part of current week 7. How to fix this? Maybe work only with the week numbers instead of the date?Also, i don't understand how to use this line of code in the 3 fields for the KPI visualization??