Forum Discussion
DAX sub query with condition
- 3 years ago
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
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