Check your eligibility for this 50% exam voucher offer and join us for free live learning sessions to get prepared for Exam DP-700.
Get StartedDon't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.
Hi,
I have a fact table which contain data about flights:
Marketing Carrier | Operating Carrier | Passengers |
AA | AA | 100 |
AA | BB | 25 |
BB | BB | 200 |
How can I create a system where, depending on a slicer selection ("Carrier Type": either Marketing Carrier or Operating Carrier), the value being shown in a graph (for example, Sum[Passengers]) will be using either Marketing Carrier or Operating Carrier as the legend?
Expected output if Carrier Type = Marketing Carrier:
AA Passengers = 125
BB Passengers = 200
Expected output if Carrier Type = Operating Carrier:
AA Passengers = 100
BB Passengers = 225
Furthermore, how can I then use this system in a bridge table? I have multiple fact tables that I would like to all toggle between Marketing or Operating, depending on the selection.
I have thought about creating duplicate switch measures for every measure but this seems like an ineffective method. I've also tried a calculated column in the fact table that takes the value of Marketing Carrier or Operating Carrier, depending on the slicer selection, and that column would then be used in all calcs -- but that didn't work either.
Any help would be grealy appreciated!
Solved! Go to Solution.
Hi,
I am not sure if I understood your question correctly, but one of ways to create this is by using field parameter feature in power bi.
Use report readers to change visuals (preview) - Power BI | Microsoft Learn
Please check the below picture and the attached pbix file (and the link above from Microsoft about how to create field parameter).
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi @PBI12345
You can achieve this in Power BI by using a combination of a slicer table, a dynamic DAX measure, and a bridge table to unify carriers across multiple fact tables. First, create a CarrierType table that acts as the slicer for selecting between "Marketing Carrier" and "Operating Carrier":
CarrierType = DATATABLE("Carrier Type", STRING, { "Marketing Carrier", "Operating Carrier" })
Once you have this slicer, define a DAX measure that dynamically adjusts which carrier column is used in calculations. This measure will sum the passenger count based on the slicer selection:
Passengers by Carrier =
VAR SelectedCarrierType = SELECTEDVALUE('CarrierType'[Carrier Type])
RETURN
SWITCH(
SelectedCarrierType,
"Marketing Carrier",
CALCULATE(SUM(Flights[Passengers]), ALLEXCEPT(Flights, Flights[Marketing Carrier])),
"Operating Carrier",
CALCULATE(SUM(Flights[Passengers]), ALLEXCEPT(Flights, Flights[Operating Carrier])),
BLANK()
)
If you want this logic to be used across multiple fact tables without duplicating measures, introduce a bridge table that consolidates unique carriers from both Marketing and Operating Carrier fields:
Carriers = DISTINCT(
UNION(
VALUES(Flights[Marketing Carrier]),
VALUES(Flights[Operating Carrier])
)
)
Next, establish two relationships: one between Carriers[Carrier] and Flights[Marketing Carrier] (inactive) and another between Carriers[Carrier] and Flights[Operating Carrier] (inactive). Instead of using calculated columns, define a DAX measure that dynamically applies the correct relationship based on the slicer selection:
Passengers by Selected Carrier =
VAR SelectedCarrierType = SELECTEDVALUE('CarrierType'[Carrier Type])
RETURN
SWITCH(
SelectedCarrierType,
"Marketing Carrier",
CALCULATE(SUM(Flights[Passengers]), USERELATIONSHIP(Carriers[Carrier], Flights[Marketing Carrier])),
"Operating Carrier",
CALCULATE(SUM(Flights[Passengers]), USERELATIONSHIP(Carriers[Carrier], Flights[Operating Carrier])),
BLANK()
)
This approach ensures that all fact tables can dynamically switch between Marketing Carrier and Operating Carrier based on a single slicer selection, without requiring multiple versions of each measure. By leveraging USERELATIONSHIP within a bridge table, you can scale this system efficiently across multiple datasets while maintaining flexibility and avoiding redundant calculations.
Best regards,
Hi @PBI12345
You can achieve this in Power BI by using a combination of a slicer table, a dynamic DAX measure, and a bridge table to unify carriers across multiple fact tables. First, create a CarrierType table that acts as the slicer for selecting between "Marketing Carrier" and "Operating Carrier":
CarrierType = DATATABLE("Carrier Type", STRING, { "Marketing Carrier", "Operating Carrier" })
Once you have this slicer, define a DAX measure that dynamically adjusts which carrier column is used in calculations. This measure will sum the passenger count based on the slicer selection:
Passengers by Carrier =
VAR SelectedCarrierType = SELECTEDVALUE('CarrierType'[Carrier Type])
RETURN
SWITCH(
SelectedCarrierType,
"Marketing Carrier",
CALCULATE(SUM(Flights[Passengers]), ALLEXCEPT(Flights, Flights[Marketing Carrier])),
"Operating Carrier",
CALCULATE(SUM(Flights[Passengers]), ALLEXCEPT(Flights, Flights[Operating Carrier])),
BLANK()
)
If you want this logic to be used across multiple fact tables without duplicating measures, introduce a bridge table that consolidates unique carriers from both Marketing and Operating Carrier fields:
Carriers = DISTINCT(
UNION(
VALUES(Flights[Marketing Carrier]),
VALUES(Flights[Operating Carrier])
)
)
Next, establish two relationships: one between Carriers[Carrier] and Flights[Marketing Carrier] (inactive) and another between Carriers[Carrier] and Flights[Operating Carrier] (inactive). Instead of using calculated columns, define a DAX measure that dynamically applies the correct relationship based on the slicer selection:
Passengers by Selected Carrier =
VAR SelectedCarrierType = SELECTEDVALUE('CarrierType'[Carrier Type])
RETURN
SWITCH(
SelectedCarrierType,
"Marketing Carrier",
CALCULATE(SUM(Flights[Passengers]), USERELATIONSHIP(Carriers[Carrier], Flights[Marketing Carrier])),
"Operating Carrier",
CALCULATE(SUM(Flights[Passengers]), USERELATIONSHIP(Carriers[Carrier], Flights[Operating Carrier])),
BLANK()
)
This approach ensures that all fact tables can dynamically switch between Marketing Carrier and Operating Carrier based on a single slicer selection, without requiring multiple versions of each measure. By leveraging USERELATIONSHIP within a bridge table, you can scale this system efficiently across multiple datasets while maintaining flexibility and avoiding redundant calculations.
Best regards,
Thanks DataNinja -- this approach worked well, and was ultimately what I needed given I already had a parameter passing a Top N value to a calculation.
Is there a way to get around having to create essentially two measures for each calculation? Ie. the first original calculation, and then the second measure which calculates the first based on the correct relationship?
Hi,
I am not sure if I understood your question correctly, but one of ways to create this is by using field parameter feature in power bi.
Use report readers to change visuals (preview) - Power BI | Microsoft Learn
Please check the below picture and the attached pbix file (and the link above from Microsoft about how to create field parameter).
If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.
Hi Jihwan,
Thank you for taking the time to create a .pbix file to show me a worked example.
Whilst your method did work (as per my instructions), I ultimately ended up using the other user's approach in my project due to a complication in my calcuations - I already am using a parameter to pass a "Top N" value, and this didn't interact correctly with the new parameter I built with your method.
Thanks again for help -- I will be using this approach in the future.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.
Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.
User | Count |
---|---|
18 | |
15 | |
11 | |
11 | |
8 |
User | Count |
---|---|
24 | |
18 | |
12 | |
11 | |
10 |