Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
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!
Check out the September 2024 Power BI update to learn about new features.
Learn from experts, get hands-on experience, and win awesome prizes.
User | Count |
---|---|
25 | |
18 | |
17 | |
17 | |
17 |
User | Count |
---|---|
30 | |
25 | |
18 | |
15 | |
13 |