Calculation Group Where SELECTEDMEASURE
Calculation Group Where SELECTEDMEASURE
the selected Sales or Inventory metrics, while also handling multi-select options from both
slicers.
🛠 Solution Overview
1️⃣ Slicers:
Sales Metrics Slicer: Total Sales $, Total Sales Cost $, Total Sales Unit
Inventory Metrics Slicer: Total RTV Rtl $, Total RTV Cost, Total RTV Units
LLY (Two Years Ago): Filters data for two years ago.
VAR _SelectedSalesMetrics =
VAR _SelectedInventoryMetrics =
VAR _DateFilter =
SWITCH(
"LY", SAMEPERIODLASTYEAR(DATESYTD('Date'[Date])),
BLANK()
VAR _FilteredMeasure =
SWITCH(
TRUE(),
SELECTEDMEASURE()
RETURN
_FilteredMeasure
1. Captures the selected values from both the Sales and Inventory slicers using
VALUES().
3. Applies the correct time-based filter (TY, LY, LLY) based on the calculation group.
4. Filters data based on whether the selected measure belongs to Sales or Inventory.
🔹 Expected Behavior
If the user selects "Total Sales $", it applies the TY/LY/LLY filter to Sales Data.
If the user selects "Total RTV Cost", it applies the TY/LY/LLY filter to Inventory Data.
If the user selects both "Total Sales $" and "Total RTV Cost", both are filtered
accordingly.
🚀 Next Steps
1. Create a disconnected table for Sales Metrics Table and Inventory Metrics Table to
store available metrics.
Would you like additional modifications, such as handling ALL selections or default
behaviors? 😊
Here’s the complete DAX code for setting up the required tables, slicers, and measures in
Power BI.
SalesMetricsTable =
DATATABLE(
"Metric", STRING,
)
🟢 Step 2: Create Inventory Metrics Table (Disconnected)
InventoryMetricsTable =
DATATABLE(
"Metric", STRING,
This measure stores multi-selected values from the Sales Metrics slicer.
SelectedSalesMetrics =
RETURN
IF(COUNTROWS(_Selected) = COUNTROWS(ALL(SalesMetricsTable[Metric])),
"All",
🔹 If all metrics are selected, it returns "All"; otherwise, it concatenates the selected metrics.
SelectedInventoryMetrics =
RETURN
IF(COUNTROWS(_Selected) = COUNTROWS(ALL(InventoryMetricsTable[Metric])),
"All",
VAR _SelectedSalesMetrics =
VALUES(SalesMetricsTable[Metric])
VAR _SelectedInventoryMetrics =
VALUES(InventoryMetricsTable[Metric])
VAR _DateFilter =
SWITCH(
"TY", DATESYTD('Date'[Date]),
"LY", SAMEPERIODLASTYEAR(DATESYTD('Date'[Date])),
BLANK()
VAR _FilteredMeasure =
SWITCH(
TRUE(),
NOT ISEMPTY(_SelectedSalesMetrics),
NOT ISEMPTY(_SelectedInventoryMetrics),
SELECTEDMEASURE()
RETURN
_FilteredMeasure
o SalesMetricsTable[Metric]
o InventoryMetricsTable[Metric]
2. Use a visual (like a table or chart) and add measures (e.g., Total Sales $, Total RTV
Cost).
🎯 Expected Behavior