Forum Discussion
Dynamic comparison tables using separate date filters
- 5 years ago
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
Metrics:
Calendar 1(a calculated table):
Calendar 1 = CALENDARAUTO()Calendar 2(a calculated table):
Calendar 1 = CALENDARAUTO()There is no relationship between tables. You may create two measures as below.
Period 1 totals = IF( HASONEVALUE(Metrics[Metric]), IF( SELECTEDVALUE(Metrics[Metric])="Cost", CALCULATE( SUM('Table'[Cost]), FILTER( ALL('Table'), [Date] in DISTINCT('Calendar 1'[Date]) ) ), CALCULATE( SUM('Table'[Click]), FILTER( ALL('Table'), [Date] in DISTINCT('Calendar 1'[Date]) ) ) ) )Period 2 totals = IF( HASONEVALUE(Metrics[Metric]), IF( SELECTEDVALUE(Metrics[Metric])="Cost", CALCULATE( SUM('Table'[Cost]), FILTER( ALL('Table'), [Date] in DISTINCT('Calendar 2'[Date]) ) ), CALCULATE( SUM('Table'[Click]), FILTER( ALL('Table'), [Date] in DISTINCT('Calendar 2'[Date]) ) ) ) )Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi, Anonymous
Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.
Table:
Metrics:
Calendar 1(a calculated table):
Calendar 1 = CALENDARAUTO()
Calendar 2(a calculated table):
Calendar 1 = CALENDARAUTO()
There is no relationship between tables. You may create two measures as below.
Period 1 totals =
IF(
HASONEVALUE(Metrics[Metric]),
IF(
SELECTEDVALUE(Metrics[Metric])="Cost",
CALCULATE(
SUM('Table'[Cost]),
FILTER(
ALL('Table'),
[Date] in DISTINCT('Calendar 1'[Date])
)
),
CALCULATE(
SUM('Table'[Click]),
FILTER(
ALL('Table'),
[Date] in DISTINCT('Calendar 1'[Date])
)
)
)
)Period 2 totals =
IF(
HASONEVALUE(Metrics[Metric]),
IF(
SELECTEDVALUE(Metrics[Metric])="Cost",
CALCULATE(
SUM('Table'[Cost]),
FILTER(
ALL('Table'),
[Date] in DISTINCT('Calendar 2'[Date])
)
),
CALCULATE(
SUM('Table'[Click]),
FILTER(
ALL('Table'),
[Date] in DISTINCT('Calendar 2'[Date])
)
)
)
)
Result:
Best Regards
Allan
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- Anonymous5 years agoNot applicable
Thanks for this!
It works well, except I can't use filters on the data. I guess due to the ALL function, or because the metrics table isn't connected to the main facts table. Is there a way around this, so I could filter by account_name for example in the facts table. At moment, if I do filter for this, it just gives overall total, and is same for each account_name.
Thanks,
Chris