Forum Discussion
Column with data type issue
- 1 year ago
Hi,
I understand what you're trying to achieve. Essentially, you need a Calculated Amount column that behaves differently based on the value selected from a slicer for your flag column. Here’s how you can approach this in Power BI using DAX.
To achieve your requirement, you’ll need to:
- Create a calculated column that gives the correct value depending on the slicer selection.
- Handle different scenarios for visualization in a Table Chart and a Card.
Here’s a step-by-step solution for your case:
Step 1: Create a New Calculated Column
You need to create a calculated column that returns Amount if the flag is A, and NA if the flag is B.
CalculatedAmount =
VAR SelectedFlag = SELECTEDVALUE('Table'[Flag])
RETURN
IF (
SelectedFlag = "A",
'Table'[Amount],
BLANK()
)Step 2: Create a Measure for Your Card and Table Visuals
To show the correct value in the table or a card, we need to create a measure that dynamically handles what is displayed based on the slicer selection.
CalculatedAmountMeasure =
VAR SelectedFlag = SELECTEDVALUE('Table'[Flag])
RETURN
SWITCH (
TRUE(),
SelectedFlag = "A", SUM('Table'[Amount]),
SelectedFlag = "B", "NA",
BLANK()
)Step 3: Using This in Visuals
- Table Visual: Add the CalculatedAmount column. This will show either the Amount value for flag A or BLANK() (which will be visually represented as an empty field for flag B).
- Card Visual: Use the CalculatedAmountMeasure for the card visual. This will dynamically change based on the slicer selection and show the correct aggregation or NA for flag B.
Good luck my friend!!
- 1 year ago
Hi Anonymous ,
First create a measure for calculated Amount by the code:
Calculated Amount = IF ( SELECTEDVALUE('YourTable'[Flag]) = "A", SUM('YourTable'[Amount]), BLANK() )And then create a measure to handle "NA" for Flag B by the code:
Display Amount = IF ( SELECTEDVALUE('YourTable'[Flag]) = "B", "NA", [Calculated Amount] )This approach ensures that the measure responds dynamically to the slicer selection and that "NA" displays only when "B" is selected. Let me know if you run into any issues with this!
If this help you, please give a kudo and mark as solution
Hi,
I understand what you're trying to achieve. Essentially, you need a Calculated Amount column that behaves differently based on the value selected from a slicer for your flag column. Here’s how you can approach this in Power BI using DAX.
To achieve your requirement, you’ll need to:
- Create a calculated column that gives the correct value depending on the slicer selection.
- Handle different scenarios for visualization in a Table Chart and a Card.
Here’s a step-by-step solution for your case:
Step 1: Create a New Calculated Column
You need to create a calculated column that returns Amount if the flag is A, and NA if the flag is B.
CalculatedAmount =
VAR SelectedFlag = SELECTEDVALUE('Table'[Flag])
RETURN
IF (
SelectedFlag = "A",
'Table'[Amount],
BLANK()
)
Step 2: Create a Measure for Your Card and Table Visuals
To show the correct value in the table or a card, we need to create a measure that dynamically handles what is displayed based on the slicer selection.
CalculatedAmountMeasure =
VAR SelectedFlag = SELECTEDVALUE('Table'[Flag])
RETURN
SWITCH (
TRUE(),
SelectedFlag = "A", SUM('Table'[Amount]),
SelectedFlag = "B", "NA",
BLANK()
)
Step 3: Using This in Visuals
- Table Visual: Add the CalculatedAmount column. This will show either the Amount value for flag A or BLANK() (which will be visually represented as an empty field for flag B).
- Card Visual: Use the CalculatedAmountMeasure for the card visual. This will dynamically change based on the slicer selection and show the correct aggregation or NA for flag B.
Good luck my friend!!