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
I have these two measures:
$ Costo No Filter = CALCULATE(SUM(EjecPtal[Valor COP])*-1,USERELATIONSHIP(Dates[Date], EjecPtal[Date]))
$ Costo Comercial = CALCULATE(SUM(EjecPtal[Valor COP])*-1, FILTER(EjecPtal, EjecPtal[CLIENTE] = "COMERCIAL"), USERELATIONSHIP(Dates[Date], EjecPtal[Date]))
$ Costo Externo = CALCULATE(SUM(EjecPtal[Valor COP])*-1, USERELATIONSHIP(Dates[Date], EjecPtal[Date]), FILTER(EjecPtal, EjecPtal[SUBORIGEN] = "COSTO EXTERNO"))
$ Costo Comercial 2 = CALCULATE(SUM(EjecPtal[Valor COP])*-1, USERELATIONSHIP(Dates[Date], EjecPtal[Date]), FILTER(EjecPtal, EjecPtal[SUBORIGEN] = "Costo nómina comercial"))
Solved! Go to Solution.
This won't work, buuuut it leaded me to play with chatgpt and find out the solution!
Basically CALCULATE can take a filter as a parameter:
$ Costo Comercial = CALCULATE(
SUM(EjecPtal[Valor COP]) * -1,
USERELATIONSHIP(Dates[Date], EjecPtal[Date]),
EjecPtal[CLIENTE] = "COMERCIAL"
)
A final note would be that DAX Query View will write EXACTLY the same for both:
$ Costo Comercial = CALCULATE( SUM(EjecPtal[Valor COP]) * -1, USERELATIONSHIP(Dates[Date], EjecPtal[Date]), EjecPtal[CLIENTE] = "COMERCIAL")
$ Costo Comercial 2 = CALCULATE(SUM(EjecPtal[Valor COP])*-1, FILTER(EjecPtal, EjecPtal[CLIENTE] = "COMERCIAL"), USERELATIONSHIP(Dates[Date], EjecPtal[Date]))
DEFINE
VAR __DS0FilterTable =
TREATAS({"COMERCIAL"}, 'EjecPtal'[CLIENTE])
VAR __DS0FilterTable2 =
TREATAS(
{"Ene. 2024",
"Feb. 2024",
"Mar. 2024",
"Abr. 2024",
"May. 2024",
"Jun. 2024",
"Jul. 2024"},
'Dates'[Month & Year]
)
VAR __DS0FilterTable3 =
FILTER(
KEEPFILTERS(VALUES('Project'[Name])),
NOT('Project'[Name] IN {"Base Project Template",
"Project 1"})
)
EVALUATE
SUMMARIZECOLUMNS(
__DS0FilterTable,
__DS0FilterTable2,
__DS0FilterTable3,
"v__Costo_Comercial", IGNORE('EjecPtal'[$ Costo Comercial]) // here it would change the names to Costo Comercial 2
)
And the table will call both with the same context:
DEFINE
VAR __DS0FilterTable =
TREATAS({"COMERCIAL"}, 'EjecPtal'[CLIENTE])
VAR __DS0FilterTable2 =
TREATAS(
{"Ene. 2024",
"Feb. 2024",
"Mar. 2024",
"Abr. 2024",
"May. 2024",
"Jun. 2024",
"Jul. 2024"},
'Dates'[Month & Year]
)
VAR __DS0FilterTable3 =
FILTER(
KEEPFILTERS(VALUES('Project'[Name])),
NOT('Project'[Name] IN {"Base Project Template",
"Project 1"})
)
VAR __DS0Core =
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL(
ROLLUPGROUP('Dates'[Month & Year], 'Dates'[Month], 'EjecPtal'[CLIENTE], 'Dates'[Date]), "IsGrandTotalRowTotal"
),
__DS0FilterTable,
__DS0FilterTable2,
__DS0FilterTable3,
"v__Costo_Comercial_2", 'EjecPtal'[$ Costo Comercial 2],
"v__Costo_Comercial", 'EjecPtal'[$ Costo Comercial]
)
VAR __DS0PrimaryWindowed =
TOPN(
502,
__DS0Core,
[IsGrandTotalRowTotal],
0,
'Dates'[Month],
1,
'Dates'[Month & Year],
1,
'EjecPtal'[CLIENTE],
1,
'Dates'[Date],
1
)
EVALUATE
__DS0PrimaryWindowed
ORDER BY
[IsGrandTotalRowTotal] DESC,
'Dates'[Month],
'Dates'[Month & Year],
'EjecPtal'[CLIENTE],
'Dates'[Date]
Really ood behaviour, I obviously must be unseeing something. Even GPT agrees that using FILTER would work better at row level rather that filtering as a parameter to CALCULATE.
Does this will show at row level, but not at total?
$ Costo Comercial =
VAR one = CALCULATE(SUM(EjecPtal[Valor COP])*-1, USERELATIONSHIP(Dates[Date], EjecPtal[Date])
RETURN
IF(EjecPtal[CLIENTE] = "COMERCIAL", one, BLANK())
This won't work, buuuut it leaded me to play with chatgpt and find out the solution!
Basically CALCULATE can take a filter as a parameter:
$ Costo Comercial = CALCULATE(
SUM(EjecPtal[Valor COP]) * -1,
USERELATIONSHIP(Dates[Date], EjecPtal[Date]),
EjecPtal[CLIENTE] = "COMERCIAL"
)
A final note would be that DAX Query View will write EXACTLY the same for both:
$ Costo Comercial = CALCULATE( SUM(EjecPtal[Valor COP]) * -1, USERELATIONSHIP(Dates[Date], EjecPtal[Date]), EjecPtal[CLIENTE] = "COMERCIAL")
$ Costo Comercial 2 = CALCULATE(SUM(EjecPtal[Valor COP])*-1, FILTER(EjecPtal, EjecPtal[CLIENTE] = "COMERCIAL"), USERELATIONSHIP(Dates[Date], EjecPtal[Date]))
DEFINE
VAR __DS0FilterTable =
TREATAS({"COMERCIAL"}, 'EjecPtal'[CLIENTE])
VAR __DS0FilterTable2 =
TREATAS(
{"Ene. 2024",
"Feb. 2024",
"Mar. 2024",
"Abr. 2024",
"May. 2024",
"Jun. 2024",
"Jul. 2024"},
'Dates'[Month & Year]
)
VAR __DS0FilterTable3 =
FILTER(
KEEPFILTERS(VALUES('Project'[Name])),
NOT('Project'[Name] IN {"Base Project Template",
"Project 1"})
)
EVALUATE
SUMMARIZECOLUMNS(
__DS0FilterTable,
__DS0FilterTable2,
__DS0FilterTable3,
"v__Costo_Comercial", IGNORE('EjecPtal'[$ Costo Comercial]) // here it would change the names to Costo Comercial 2
)
And the table will call both with the same context:
DEFINE
VAR __DS0FilterTable =
TREATAS({"COMERCIAL"}, 'EjecPtal'[CLIENTE])
VAR __DS0FilterTable2 =
TREATAS(
{"Ene. 2024",
"Feb. 2024",
"Mar. 2024",
"Abr. 2024",
"May. 2024",
"Jun. 2024",
"Jul. 2024"},
'Dates'[Month & Year]
)
VAR __DS0FilterTable3 =
FILTER(
KEEPFILTERS(VALUES('Project'[Name])),
NOT('Project'[Name] IN {"Base Project Template",
"Project 1"})
)
VAR __DS0Core =
SUMMARIZECOLUMNS(
ROLLUPADDISSUBTOTAL(
ROLLUPGROUP('Dates'[Month & Year], 'Dates'[Month], 'EjecPtal'[CLIENTE], 'Dates'[Date]), "IsGrandTotalRowTotal"
),
__DS0FilterTable,
__DS0FilterTable2,
__DS0FilterTable3,
"v__Costo_Comercial_2", 'EjecPtal'[$ Costo Comercial 2],
"v__Costo_Comercial", 'EjecPtal'[$ Costo Comercial]
)
VAR __DS0PrimaryWindowed =
TOPN(
502,
__DS0Core,
[IsGrandTotalRowTotal],
0,
'Dates'[Month],
1,
'Dates'[Month & Year],
1,
'EjecPtal'[CLIENTE],
1,
'Dates'[Date],
1
)
EVALUATE
__DS0PrimaryWindowed
ORDER BY
[IsGrandTotalRowTotal] DESC,
'Dates'[Month],
'Dates'[Month & Year],
'EjecPtal'[CLIENTE],
'Dates'[Date]
Really ood behaviour, I obviously must be unseeing something. Even GPT agrees that using FILTER would work better at row level rather that filtering as a parameter to CALCULATE.
Hi! @daniq
This could be due to some gap in data model relationship or some filters flowing through, if you can share the sample data with desired solution then I can have a look at it. Also, make sure you are not sharing in sensitive data.
HI, I've just found out the solution and posted it to FLiflop1 answer. It was indeed a filtering issue, just can't understand why exactly.
Thanks!
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 |
---|---|
23 | |
16 | |
15 | |
7 | |
6 |
User | Count |
---|---|
33 | |
29 | |
16 | |
13 | |
12 |