The ultimate Microsoft Fabric, Power BI, Azure AI, and SQL learning event: Join us in Stockholm, September 24-27, 2024.
Save €200 with code MSCUST on top of early bird pricing!
Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started
I've got this measure which is working in the view. This is a calculated table.
But when I add a Data Card to do a DISTINCTCOUNT on IDs, and add the DatesOkay measure to the data card's filter, it won't let me do anything with it. I want to be able to filter my data card by DatesOkay = "YES". Clicking on Contains does nothing, and I can't add YES...liked it's locked or something, and it's not.
I'm assuming I have to create the column in the calculated table DAX, but can't seem to get it to work. Here's the table language...
Solved! Go to Solution.
Adding this into your card visual I think should work:
Distinct Ids With Okay Dates =
CALCULATE (
DISTINCTCOUNT ( CTab[Client_Id] ),
FILTER (
CTab,
CTab[End Date] > CTab[Start Date]
)
)
Actually moving the logic into your calculated table will be more efficient:
CTab =
ADDCOLUMNS (
ADDCOLUMNS (
SUMMARIZE ( GAD_PHQ, GAD_PHQ[Client_ID], GAD_PHQ[Assess_Type] ),
"Start Date", CALCULATE ( MIN ( GAD_PHQ[Assess_Date] ) ),
"End Date", CALCULATE ( MAX ( GAD_PHQ[Assess_Date] ) )
),
"Start Score",
VAR _current_asset_type = GAD_PHQ[Assess_Type]
VAR _current_start_date = [Start Date]
RETURN
CALCULATE (
AVERAGE ( GAD_PHQ[Assess_Score] ),
GAD_PHQ[Assess_Date] = _current_start_date,
GAD_PHQ[Assess_Type] = _current_asset_type
),
"End Score",
VAR _current_asset_type = GAD_PHQ[Assess_Type]
VAR _current_end_date = [End Date]
RETURN
CALCULATE (
AVERAGE ( GAD_PHQ[Assess_Score] ),
GAD_PHQ[Assess_Date] = _current_end_date,
GAD_PHQ[Assess_Type] = _current_asset_type
),
"Dates Okay",
IF (
[End Date] > [Start Date],
"Yes",
"No"
)
)
The measure can then filter a plane distinct count or write a measure like:
Distinct Ids With Okay Dates =
CALCULATE (
DISTINCTCOUNT ( CTab[Client_Id] ),
CTab[Dates Okay] = "Yes"
)
Adding this into your card visual I think should work:
Distinct Ids With Okay Dates =
CALCULATE (
DISTINCTCOUNT ( CTab[Client_Id] ),
FILTER (
CTab,
CTab[End Date] > CTab[Start Date]
)
)
Like magic. Thank you!!!!
Actually moving the logic into your calculated table will be more efficient:
CTab =
ADDCOLUMNS (
ADDCOLUMNS (
SUMMARIZE ( GAD_PHQ, GAD_PHQ[Client_ID], GAD_PHQ[Assess_Type] ),
"Start Date", CALCULATE ( MIN ( GAD_PHQ[Assess_Date] ) ),
"End Date", CALCULATE ( MAX ( GAD_PHQ[Assess_Date] ) )
),
"Start Score",
VAR _current_asset_type = GAD_PHQ[Assess_Type]
VAR _current_start_date = [Start Date]
RETURN
CALCULATE (
AVERAGE ( GAD_PHQ[Assess_Score] ),
GAD_PHQ[Assess_Date] = _current_start_date,
GAD_PHQ[Assess_Type] = _current_asset_type
),
"End Score",
VAR _current_asset_type = GAD_PHQ[Assess_Type]
VAR _current_end_date = [End Date]
RETURN
CALCULATE (
AVERAGE ( GAD_PHQ[Assess_Score] ),
GAD_PHQ[Assess_Date] = _current_end_date,
GAD_PHQ[Assess_Type] = _current_asset_type
),
"Dates Okay",
IF (
[End Date] > [Start Date],
"Yes",
"No"
)
)
The measure can then filter a plane distinct count or write a measure like:
Distinct Ids With Okay Dates =
CALCULATE (
DISTINCTCOUNT ( CTab[Client_Id] ),
CTab[Dates Okay] = "Yes"
)
Disregard!
I need one more calculation to bring this home.
I need a column that I can filter on that indicates that the End Score is less than the Start Score. I tried to replicate the Dates Okay syntax, but the table DAX isn't recognizing the [End Date] or [Start Date]. When I use "End Date" and "Start Date" they all come back "YES".
I was able to make another calculation to make this work (not in the table, but...)
If you wanted to reference those columns you'd need another nested addcolumns before you do it. In my opinion that starts to get messy so would be better to try and refactor the whole thing using a set of variables. I'm out at the moment but will give it when I'm back.
Hard to test I've not done some silly but I think this is what you want:
CTab =
GENERATE (
SUMMARIZE ( GAD_PHQ, GAD_PHQ[Client_ID], GAD_PHQ[Assess_Type] ),
VAR _StartDate =
CALCULATE ( MIN ( GAD_PHQ[Assess_Date] ) )
VAR _EndDate =
CALCULATE ( MAX ( GAD_PHQ[Assess_Date] ) )
VAR _current_asset_type = GAD_PHQ[Assess_Type]
VAR _current_start_date = [Start Date]
VAR _StartScore =
CALCULATE (
AVERAGE ( GAD_PHQ[Assess_Score] ),
GAD_PHQ[Assess_Date] = _current_start_date,
GAD_PHQ[Assess_Type] = _current_asset_type
)
VAR _current_asset_type = GAD_PHQ[Assess_Type]
VAR _current_end_date = [End Date]
VAR _EndScore =
CALCULATE (
AVERAGE ( GAD_PHQ[Assess_Score] ),
GAD_PHQ[Assess_Date] = _current_end_date,
GAD_PHQ[Assess_Type] = _current_asset_type
)
VAR _DatesOkay =
IF ( _EndDate > _StartDate, "Yes", "No" )
VAR _Improved =
IF ( _EndScore > _StartScore, "Yes", "No" )
RETURN
ROW (
"Start Date", _StartDate,
"End Date", _EndDate,
"Start Score", _StartScore,
"End Score", _EndScore,
"Dates Okay", _DatesOkay,
"Improved", _Improved
)
)
Even better. They both work, but I like the idea of integrating into the table. Thank you!!!!!
I can filter on the table without issue, but I can't apply the DatesOkay filter to a data card to get a count of IDs where DatesOkay = YES.
Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.
Check out the August 2024 Power BI update to learn about new features.
User | Count |
---|---|
119 | |
86 | |
75 | |
55 | |
44 |
User | Count |
---|---|
136 | |
128 | |
78 | |
64 | |
63 |