The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi team,
requiremnet : In a text box, I dynamically need to show country name, where the "SC" value is minimum for selected period[month-year] in slicer.
Data available :
I have dim country table with country column.
"SC_measure" is a measure that gets calculated at run time only. country table and the "SC" measure do not have any direct/indirect relationship.
Period is a calculated table and [Month-Year] is a calculated column fetching data as "Jan-fy24", "Feb-FY24" and so on...
I have written 2 DAX formulae.
1. To fetch min sc value for selected period
===============
2. DAX to fetch Country name where SC is minimum based on selected period[month-year] in slicer, and the country should not be blank or NA
Solved! Go to Solution.
HI @rajendraongole1
The below single DAX worked to fetch the country for min sc_measure.
MinimumSCMeasureAcrossCountries =
VAR Countries =
SUMMARIZE(
DimCountry,
DimCountry[country]
)
VAR MinSCMeasure =
MINX(
Countries,
[SC_Measure]
)
VAR MinSCMeasureUnit =
SELECTCOLUMNS(
FILTER(
Countries,
[SC_Measure] = MinSCMeasure
),
"country", DimCountry[country]
)
RETURN
MinSCMeasureUnit
Hi @Sania-F -Try the below create measure to calculates the minimum SC value
Min_SC =
VAR SelectedPeriod = SELECTEDVALUE(period[Month-year])
RETURN
CALCULATE(
MINX('Measure Table', [SC_measure]),
period[Month-year] = SelectedPeriod
)
Create another measure to calculate the countries correctly with minimum one SC value.
CountryNameWithMinSC =
VAR SelectedPeriod = SELECTEDVALUE(period[Month-year])
VAR MinValue = [Min_SC]
RETURN
MAXX(
FILTER(
ADDCOLUMNS(
DimCountry,
"SCValue", CALCULATE(
[SC_measure],
period[Month-year] = SelectedPeriod
)
),
NOT ISBLANK([SCValue]) &&
[SCValue] = MinValue
),
DimCountry[country]
)
I hope the above approach works.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Proud to be a Super User! | |
hi @rajendraongole1
I tried the above DAX but its not working.
I strongly feel that something needs to be fixed with DAX 1 measure , because the 1st dax is not returning any value, when I try to see in a card/table what value is it returning
Min_SC =
VAR SelectedPeriod = SELECTEDVALUE(period[Month-year])
RETURN
CALCULATE(
MINX('Measure Table', [SC_measure]),
period[Month-year] = SelectedPeriod
)
I also tried to eliminate/ignore if there are any blank values while fetchinh min sc value, but still not working. it just returns blank. any idea what may be going wrong.
Hi @Sania-F - Can you try below measure for DAX1 AND DAX2:
Changed logic using treatas If your tables do not have a direct relationship, use the function to apply the filter context
Min_SC =
VAR SelectedPeriod = SELECTEDVALUE(period[Month-Year])
RETURN
CALCULATE(
MINX('Measure Table', [SC_measure]),
TREATAS( { SelectedPeriod }, 'Measure Table'[Month-Year] )
)
Dax2: modified one.
CountryNameWithMinSC =
VAR SelectedPeriod = SELECTEDVALUE(period[Month-Year])
VAR MinValue = [Min_SC]
RETURN
MAXX(
FILTER(
CROSSJOIN(DimCountry, 'Measure Table'),
NOT ISBLANK(DimCountry[country]) &&
DimCountry[country] <> "NA" &&
'Measure Table'[Month-Year] = SelectedPeriod &&
[SC_measure] = MinValue
),
DimCountry[country]
)
Try above and let know.
Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!!
Proud to be a Super User! | |
HI @rajendraongole1
The below single DAX worked to fetch the country for min sc_measure.
MinimumSCMeasureAcrossCountries =
VAR Countries =
SUMMARIZE(
DimCountry,
DimCountry[country]
)
VAR MinSCMeasure =
MINX(
Countries,
[SC_Measure]
)
VAR MinSCMeasureUnit =
SELECTCOLUMNS(
FILTER(
Countries,
[SC_Measure] = MinSCMeasure
),
"country", DimCountry[country]
)
RETURN
MinSCMeasureUnit
User | Count |
---|---|
58 | |
54 | |
53 | |
49 | |
30 |
User | Count |
---|---|
177 | |
88 | |
70 | |
48 | |
48 |