Forum Discussion

JCG99's avatar
JCG99
Regular Visitor
2 years ago
Solved

Grouping with gaps

Hello,
I am trying to group data with gaps inside them. This is a sample of my data:

 

distance fromdistance to built year Type road Living area ZoneState 
0101990AlleyYesAGood
10151990AlleyYesAGood
20251995AlleyYesAGood
30601995Street ABad
60711990  ABad
1001202020  A 
3003701995HighwayNo B 
3704002020HighwayNo B 

I want to group my values by 'distnace from' and 'distance to' in a table. I have defined field paramters that the user would choose to display on the table:

 

The problem is that it doesn't not diaply the right data when there are gaps. Take for instance the case when I display the built year.

This is what I get by using min/max for the distance from and distance to (renamed measure_from/measure_to, as it is now a measure):

 

 Measure_fromMeasure_tobuilt year 

0711990
203701995
1004002020

And I should be getting this:

 

Measure_fromMeasure_tobuilt year 

0151990
20251995
30601995
60711990
1001202020
3003701995
3704002020
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi JCG99 

    Please try the following DAX:

    Min from = 
    VAR _selectyear =  SELECTEDVALUE('Table'[built year ])
    VAR _selecttype = SELECTEDVALUE('Table'[Type road ])
    RETURN
    MINX(FILTER(ALL('Table'),'Table'[built year ] = _selectyear && 'Table'[Type road ]=_selecttype),'Table'[distance from])
    Max to = 
    VAR _selectyear =  SELECTEDVALUE('Table'[built year ])
    VAR _selecttype = SELECTEDVALUE('Table'[Type road ])
    RETURN
    MAXX(FILTER(ALL('Table'),'Table'[built year ] = _selectyear && 'Table'[Type road ]=_selecttype),'Table'[distance to ])

     

    Result:

     

     

     

     

    Best Regards,

    Jayleny

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi JCG99 

    Please try the following DAX:

    Min from = 
    VAR _selectyear =  SELECTEDVALUE('Table'[built year ])
    VAR _selecttype = SELECTEDVALUE('Table'[Type road ])
    RETURN
    MINX(FILTER(ALL('Table'),'Table'[built year ] = _selectyear && 'Table'[Type road ]=_selecttype),'Table'[distance from])
    Max to = 
    VAR _selectyear =  SELECTEDVALUE('Table'[built year ])
    VAR _selecttype = SELECTEDVALUE('Table'[Type road ])
    RETURN
    MAXX(FILTER(ALL('Table'),'Table'[built year ] = _selectyear && 'Table'[Type road ]=_selecttype),'Table'[distance to ])

     

    Result:

     

     

     

     

    Best Regards,

    Jayleny

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

  • JCG99's avatar
    JCG99
    Regular Visitor

    Thanks for the answer. The grouping works good when the column buitl year and type road are selected, but not in other configuration. 

    For instance, when only built year is selected, I get this result: 

    However, I expect to get all type of road:

    0 -> 25 Alley

    30 -> 60 Street 

    60 -> 120 /

    300 -> 400 Highway