Don't miss your chance to take the Fabric Data Engineer (DP-600) exam for FREE! Find out how by attending the DP-600 session on April 23rd (pacific time), live or on-demand.
Learn moreNext up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now
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
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 7 | |
| 6 | |
| 3 | |
| 2 | |
| 2 |
| User | Count |
|---|---|
| 21 | |
| 12 | |
| 9 | |
| 5 | |
| 5 |