March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello Team,
I need DAX for creating Exceptions(based on month selection filter {Total submissions on selected month- Last week submissions})
Currently, I'm using DAX like below mentioned:
NOTE: Calu Month = week num-1
After using this DAX(), associative property not working.
Solved! Go to Solution.
Hi @Anonymous ,
We can use the following steps to meet your requirement.
1. We need to create three calculate columns to get month, month number and week num.
Month = FORMAT('query(16)'[Modified],"mmm")
Month number = MONTH('query(16)'[Modified])
week num = WEEKNUM('query(16)'[Modified],2)
2. Then we can create the following measures to get the Total and Exceptions.
Total submissions =
CALCULATE(COUNT('query(16)'[DU_ID]),FILTER(ALLSELECTED('query(16)'),'query(16)'[Month]=MAX('query(16)'[Month])))
Exceptions =
var _max_week = CALCULATE(MAX('query(16)'[week num]),FILTER(ALLSELECTED('query(16)'),'query(16)'[Month]=MAX('query(16)'[Month])))
return
CALCULATE(COUNT('query(16)'[DU_ID]),FILTER(ALLSELECTED('query(16)'),'query(16)'[week num]=_max_week))
new one Exception =
var _max_week = CALCULATE(MAX('query(16)'[week num]),FILTER(ALLSELECTED('query(16)'),'query(16)'[Month]=MAX('query(16)'[Month])))
return
[Total submissions] - CALCULATE(COUNT('query(16)'[DU_ID]),FILTER(ALLSELECTED('query(16)'),'query(16)'[week num]=_max_week))
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
I'm used below mentioed DAX, after working fine my Application.
Hi @Anonymous ,
How about the result after you follow the suggestions mentioned in my original post?
Could you please provide more details or expected result about it If it doesn't meet your requirement?
If you've fixed the issue on your own please kindly share your solution.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello v-zhenbw-msft,
It's working current month only not for previous months. Please provide your valuable suggestions to me.
Thanks,
I.Ravi,
Cell: 8309454052
Hi @Anonymous ,
Sorry for that we can't reproduce your issue. Do you have a date table? Or do you just have a query(16) table?
Could you please provide a mockup sample based on fake data or describe the fields of each tables and the relations between tables simply?
This allows us or others to help you solve the issue.
It will be helpful if you can show us the exact expected result based on the tables.
Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello,
I'm using below mentioned DAX, it's somewhat working you can please help me to stabilize this one.
Hi @Anonymous ,
Try this measure, hope it helps.
new one Exception =
VAR _max_week =
CALCULATE (
MAX ( 'query (16)'[week num] ),
FILTER (
ALLSELECTED ( 'query (16)' ),
'query (16)'[Month] = SELECTEDVALUE ( 'query (16)'[Month] )
)
)
VAR _lastweek = _max_week - 1
VAR lastweekcount =
CALCULATE (
[Total DU],
FILTER ( ALLSELECTED ( 'query (16)' ), 'query (16)'[week num] = _lastweek )
)
RETURN
[Total DU] - lastweekcount
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello,
Your mentioned DAX giving different behavior, please find attached sample excel data.
DU_ID | Account | Modified |
MFG | TEREX | 19-06-2020 23:12 |
BFS | CITIGROUP-CTO-RISK | 09-06-2020 17:46 |
CMT | EY | 28-06-2020 11:59 |
BFS | CITIGROUP-CTO-RISK | 28-06-2020 14:54 |
CMT | TIME WARNER | 19-07-2020 15:48 |
CMT | CAMPBELL FOODS | 19-07-2020 23:35 |
CMT | P&G | 19-07-2020 18:07 |
CMT | P&G | 19-07-2020 18:02 |
MFG | CHEVRON | 19-07-2020 10:54 |
MFG | CHEVRON | 19-07-2020 03:59 |
MFG | UTC GROUP (Carrier) | 17-07-2020 18:18 |
MFG | UTC GROUP (Otis) | 19-07-2020 10:05 |
NR | SCANIA | 19-07-2020 21:15 |
NR | NETS HOLDINGS | 19-07-2020 11:18 |
NR | NETS HOLDINGS | 19-07-2020 11:21 |
NR | NETS HOLDINGS | 19-07-2020 11:27 |
NR | NETS HOLDINGS | 19-07-2020 10:54 |
NR | NETS HOLDINGS | 19-07-2020 11:09 |
NR | NETS HOLDINGS | 19-07-2020 11:17 |
INS | BB&T Insurance Services | 17-07-2020 20:17 |
INS | ONEMAIN SOLUTIONS | 17-07-2020 10:27 |
INS | ONEMAIN SOLUTIONS | 17-07-2020 10:28 |
EU | VEOLIA-WATERS | 19-07-2020 22:50 |
EU | VEOLIA-WATERS | 19-07-2020 22:54 |
BFS | CITIGROUP-ICG-MSST | 19-07-2020 21:32 |
MFG | CHEVRON | 19-07-2020 06:57 |
MFG | PBF ENERGY | 17-07-2020 12:46 |
MFG | PBF ENERGY | 17-07-2020 18:27 |
MFG | PBF ENERGY | 17-07-2020 18:23 |
MFG | PBF ENERGY | 17-07-2020 20:25 |
MFG | JCI | 19-07-2020 15:54 |
CMT | INGRAM MICRO | 17-07-2020 08:29 |
MFG | CHEVRON | 17-07-2020 03:57 |
MFG | CHEVRON | 15-07-2020 09:20 |
Europe | Lafarge | 10-07-2020 20:07 |
INS | INSURITY | 16-07-2020 19:49 |
CMT | VIACOM-CMT | 15-07-2020 00:06 |
INS | INSURITY | 19-07-2020 10:34 |
BFS | CITIGROUP-CTO-FINANCE | 17-07-2020 16:23 |
BFS | CITIGROUP-CTI-CATE | 19-07-2020 15:00 |
BFS | CITIGROUP-ICG-TTS/CPB | 17-07-2020 18:48 |
BFS | CITIGROUP-CITI-GCB | 19-07-2020 11:17 |
BFS | CITIGROUP-CTO-COMPLIANCE | 19-07-2020 21:56 |
BFS | CITIGROUP-CTO-RISK | 08-07-2020 08:13 |
BFS | CITIGROUP-CTO-RISK | 15-07-2020 14:58 |
BFS | CITIGROUP-CTO-RISK | 19-07-2020 19:54 |
NR | NETS HOLDINGS | 19-07-2020 11:25 |
NR | NETS HOLDINGS | 19-07-2020 12:21 |
NR | NETS HOLDINGS | 19-07-2020 12:30 |
NR | NETS HOLDINGS | 19-07-2020 12:36 |
NR | NETS HOLDINGS | 19-07-2020 12:39 |
MFG | Kaman | 19-07-2020 14:20 |
Thanks,
I.Ravi.,
Hi @Anonymous ,
We can use the following steps to meet your requirement.
1. We need to create three calculate columns to get month, month number and week num.
Month = FORMAT('query(16)'[Modified],"mmm")
Month number = MONTH('query(16)'[Modified])
week num = WEEKNUM('query(16)'[Modified],2)
2. Then we can create the following measures to get the Total and Exceptions.
Total submissions =
CALCULATE(COUNT('query(16)'[DU_ID]),FILTER(ALLSELECTED('query(16)'),'query(16)'[Month]=MAX('query(16)'[Month])))
Exceptions =
var _max_week = CALCULATE(MAX('query(16)'[week num]),FILTER(ALLSELECTED('query(16)'),'query(16)'[Month]=MAX('query(16)'[Month])))
return
CALCULATE(COUNT('query(16)'[DU_ID]),FILTER(ALLSELECTED('query(16)'),'query(16)'[week num]=_max_week))
new one Exception =
var _max_week = CALCULATE(MAX('query(16)'[week num]),FILTER(ALLSELECTED('query(16)'),'query(16)'[Month]=MAX('query(16)'[Month])))
return
[Total submissions] - CALCULATE(COUNT('query(16)'[DU_ID]),FILTER(ALLSELECTED('query(16)'),'query(16)'[week num]=_max_week))
If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
BTW, pbix as attached.
Hi @Anonymous ,
How about the result after you follow the suggestions mentioned in my original post?
Could you please provide more details or expected result about it If it doesn't meet your requirement?
If you've fixed the issue on your own please kindly share your solution.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
For your DAX function not working fine.
I'm used below mentioed DAX, after working fine my Application.
Hi @Anonymous ,
Here is our understanding:
The Total submissions calculate the total count DU_ID of each month.
The Exceptions calculate the total count of the previous week of the last week in each month.
For example, there are five weeks in January, then the Exceptions will calculate the total count in the fourth week.
If our understanding is correct, we can create two measure to meet your requirement.
1. First we need to create a week num column.
week num = WEEKNUM('query (16)'[Date],2)
2. Then we can create two measures to get the result.
Total submissions =
CALCULATE(COUNT('query (16)'[DU_ID]),FILTER(ALLSELECTED('query (16)'),'query (16)'[Month]=MAX('query (16)'[Month])))
Exceptions =
VAR _max_week =
CALCULATE (
MAX ( 'query (16)'[week num] ),
FILTER (
ALLSELECTED ( 'query (16)' ),
'query (16)'[Month] = MAX ( 'query (16)'[Month] )
)
)
VAR _last_week = _max_week - 1
RETURN
CALCULATE (
COUNT ( 'query (16)'[DU_ID] ),
FILTER ( ALLSELECTED ( 'query (16)' ), 'query (16)'[week num] = _last_week )
)
If it doesn’t meet your requirement, could you please provide a mockup sample based on fake data or describe the fields of each tables and the relations between tables simply?
It will be helpful if you can show us the exact expected result based on the tables.
Please upload your files to OneDrive For Business and share the link here. Please don't contain any Confidential Information or Real data in your reply.
BTW, pbix as attached.
Best regards,
Community Support Team _ zhenbw
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
@Anonymous , for week Vs Week refer my blog
How to create a week calendar
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
133 | |
90 | |
88 | |
64 | |
58 |
User | Count |
---|---|
201 | |
137 | |
107 | |
70 | |
68 |