Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi everyone,
I have been struggle for a while for a subquery in DAX. I have the following table
ID | Country | Name | Period |
ID1 | US | A | 201412 |
ID1 | US | A | 201506 |
ID1 | US | A | 201512 |
ID10 | CA | B | 201412 |
ID10 | CA | B | 201506 |
ID10 | CA | B | 201512 |
ID10 | CA | BB | 201606 |
ID10 | CA | BB | 201612 |
ID10 | CA | BB | 201706 |
ID10 | CA | BB | 201712 |
ID10 | CA | BB | 201806 |
ID10 | CA | BB | 201809 |
ID10 | CA | BB | 201812 |
ID10 | MX | C | 201712 |
ID10 | MX | C | 201806 |
ID10 | MX | CC | 201809 |
ID10 | MX | CC | 201812 |
ID100 | IE | D | 201412 |
ID100 | IE | D | 201506 |
ID100 | IE | D | 201512 |
ID100 | IE | DD | 201606 |
ID100 | IE | DD | 201612 |
ID100 | IE | DD | 201706 |
ID100 | IE | DD | 201712 |
ID100 | IE | DD | 201806 |
ID100 | IE | DD | 201809 |
ID100 | IE | DD | 201812 |
The user has one slicer, the period and can select start and end perido (for instance from 201412 - 201612). Once, the period is selected, I need to create a report that show a list of a unique items (Name). There are few condition:
This means that the output looks like:
_ID | _Country | _Name |
ID10 | CA | BB |
ID100 | IE | DD |
I have tried to write a DAX but it is not working properly
If someone could help me on this, it will be greatly appreciated.
Many thanks,
Salva
Solved! Go to Solution.
Hi , @Salva_BI_DAX
Here are the steps you can refer to :
(1)My test data is the same as yours.
(2)We can create a measure to filter our visual :
Display Flag =
var _slicer_min =CALCULATE( MIN('Table'[Period]),ALLSELECTED('Table'))
var _slicer_max=CALCULATE( MAX('Table'[Period]),ALLSELECTED('Table'))
var _slicer_count =COUNTROWS( DISTINCT( SELECTCOLUMNS( FILTER(ALL('Table') , 'Table'[Period]>=_slicer_min && 'Table'[Period] <=_slicer_max),"Period",[Period])))
var _current_id =SELECTEDVALUE('Table'[ID])
var _id_count =COUNTROWS( FILTER('Table', 'Table'[ID]=_current_id))
return
if(_id_count= _slicer_count ,1,0)
(3)Then we need to create another measure :
Name2 = var _max = MAX('Table'[Period])
var _current_id = SELECTEDVALUE('Table'[ID])
var _t =FILTER('Table', 'Table'[ID]=_current_id && 'Table'[Period]=_max)
return
MAXX(_t ,[Name])
(4)Then we need to put the [Display Flag] measure on the "Filter on this visual" and the [ID],[Country],[Name2] on the visual , the result is as follows:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Hello, @v-yueyunzh-msft
This is exactly what I was looking for 😀
Indeed, I saw in another form that the best approch is to create the measures instead to create subtable.
Many thanks
Hi , @Salva_BI_DAX
Here are the steps you can refer to :
(1)My test data is the same as yours.
(2)We can create a measure to filter our visual :
Display Flag =
var _slicer_min =CALCULATE( MIN('Table'[Period]),ALLSELECTED('Table'))
var _slicer_max=CALCULATE( MAX('Table'[Period]),ALLSELECTED('Table'))
var _slicer_count =COUNTROWS( DISTINCT( SELECTCOLUMNS( FILTER(ALL('Table') , 'Table'[Period]>=_slicer_min && 'Table'[Period] <=_slicer_max),"Period",[Period])))
var _current_id =SELECTEDVALUE('Table'[ID])
var _id_count =COUNTROWS( FILTER('Table', 'Table'[ID]=_current_id))
return
if(_id_count= _slicer_count ,1,0)
(3)Then we need to create another measure :
Name2 = var _max = MAX('Table'[Period])
var _current_id = SELECTEDVALUE('Table'[ID])
var _t =FILTER('Table', 'Table'[ID]=_current_id && 'Table'[Period]=_max)
return
MAXX(_t ,[Name])
(4)Then we need to put the [Display Flag] measure on the "Filter on this visual" and the [ID],[Country],[Name2] on the visual , the result is as follows:
If this method does not meet your needs, you can provide us with your special sample data and the desired output sample data in the form of tables, so that we can better help you solve the problem.
Best Regards,
Aniya Zhang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
45 | |
25 | |
19 | |
16 | |
8 |
User | Count |
---|---|
70 | |
48 | |
45 | |
19 | |
16 |