Forum Discussion

admin_xlsior's avatar
admin_xlsior
Icon for Post Prodigy rankPost Prodigy
5 years ago
Solved

Calculated column for group from other table

Hi guys,

 

How is the DAX looks like if I want to add calculated column for grouping my data based on grouping table ?

So I have this group table and my transactions :

Thanks,

  • Anonymous's avatar
    Anonymous
    5 years ago

    Hi admin_xlsior ,

     

    Based on your description, you cannot create calculated columns when you are in Direct Query Mode. Instead, you can create a measure as follows.

    Measure = 

    var x1=DATEDIFF(SELECTEDVALUE('Transaction'[CreateDate]),TODAY(),DAY)

    return

    MAXX(FILTER(ALL('Age Grouping'),[From]<=x1&&x1<=[To]),[Description])

    Result:

    Hope that's what you were looking for.

    Best Regards,

    Yuna

     

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

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi admin_xlsior ,

     

    Based on your description, you cannot create calculated columns when you are in Direct Query Mode. Instead, you can create a measure as follows.

    Measure = 

    var x1=DATEDIFF(SELECTEDVALUE('Transaction'[CreateDate]),TODAY(),DAY)

    return

    MAXX(FILTER(ALL('Age Grouping'),[From]<=x1&&x1<=[To]),[Description])

    Result:

    Hope that's what you were looking for.

    Best Regards,

    Yuna

     

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

    • admin_xlsior's avatar
      admin_xlsior
      Icon for Post Prodigy rankPost Prodigy

      Hi amitchandak 

       

      So sorry, one important thing I forgot here is I'm using Direct Query, so I think MAXX is not supported.

       

      Thanks,

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        admin_xlsior , Try measure like

         

        new measure =
        var _diff = datediff([created_date],today(), day) //Add +1 if needed
        return
        maxx(filter('Age Grouping',_diff >= max('Age Grouping'[from]) && 'Age Grouping',_diff <= max('Age Grouping'[to]) ), [Description])