Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Help with query DAX for adding a new column with a certain value based on simple logic

Hi Community,

 

I would like your help on a query I have and qhat DAX query I need to use to establish the following:

 

I currently (table 1) have this data. And I would like to have in the Payed Column a logic applied with would give value "Y" in case the ID also has a A2 Event or a 0 amount (same). And otherwise "N". Resulting in table 2. 

 

I'm stuck, could someone help? Much appreciated! 

 

IDEventAmountPayed
1A110 
2A120 
3A130 
4A112 
5A1368 
6A112 
7A114 
1A20 
3A20 
4A20 
5A20 

 

Table 2

 

IDEventAmountPayed
1A110Y
2A120N
3A130Y
4A112Y
5A1368Y
6A112N
7A114N
1A20Y
3A20Y
4A20Y
5A20Y

 

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new column.

     

     

    Payed CC =
    IF (
        COUNTROWS (
            FILTER (
                Data,
                Data[ID] = EARLIER ( Data[ID] )
                    && CONTAINS ( FILTER ( Data, Data[ID] = EARLIER ( Data[ID] ) ), Data[Event], "A2" )
                    && CONTAINS ( FILTER ( Data, Data[ID] = EARLIER ( Data[ID] ) ), Data[Amount], 0 )
            )
        ) > 0,
        "Y",
        "N"
    )
    
  • Hi,

    thank you for your message.

    could you please try the below? it is for creating a calculated column.

     

    Paid CC =
    VAR _IDcontainsA2 =
        SUMMARIZE ( FILTER ( Data, Data[Event] = "A2" ), Data[ID] )
    RETURN
        IF ( Data[ID] IN _IDcontainsA2, "Y", "N" )
    

3 Replies

  • Hi,

    Please check the below picture and the attached pbix file.

    It is for creating a new column.

     

     

    Payed CC =
    IF (
        COUNTROWS (
            FILTER (
                Data,
                Data[ID] = EARLIER ( Data[ID] )
                    && CONTAINS ( FILTER ( Data, Data[ID] = EARLIER ( Data[ID] ) ), Data[Event], "A2" )
                    && CONTAINS ( FILTER ( Data, Data[ID] = EARLIER ( Data[ID] ) ), Data[Amount], 0 )
            )
        ) > 0,
        "Y",
        "N"
    )
    
    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Johwan_Kim,

       

      Thanks again for your help on my previous query. The data changed a bit, and I was wondering if you could help again, sorry. BUt very much appreciated! 

      I still want to end up with the same result. Thus, I would like to have in the Payed Column a logic applied with would give value "Y" in case the ID also has a A2 Event. And otherwise "N". Resulting in table 2. 

      The yable is now as follow:

      IDEventDateAmount
      1A11-7-202210
      2A11-7-202220
      3A11-7-202230
      5A11-7-2022368
      5A21-7-20220
      7A11-7-202214
      1A42-7-2022NULL
      4A12-7-202212
      6A13-7-202212
      3A34-7-202245
      6A34-7-202218
      1A55-7-2022NULL
      4A29-7-20220
      1A210-7-20220
      3A211-7-20220

       

      And I would like it to be:

      IDEventDateAmountPayed CC
      1A11-7-202210Y
      2A11-7-202220N
      3A11-7-202230Y
      5A11-7-2022368Y
      5A21-7-20220Y
      7A11-7-202214N
      1A42-7-2022NULLY
      4A12-7-202212Y
      6A13-7-202212N
      3A34-7-202245Y
      6A34-7-202218N
      1A55-7-2022NULLY
      4A29-7-20220Y
      1A210-7-20220Y
      3A211-7-20220Y
      • Jihwan_Kim's avatar
        Jihwan_Kim
        Super User

        Hi,

        thank you for your message.

        could you please try the below? it is for creating a calculated column.

         

        Paid CC =
        VAR _IDcontainsA2 =
            SUMMARIZE ( FILTER ( Data, Data[Event] = "A2" ), Data[ID] )
        RETURN
            IF ( Data[ID] IN _IDcontainsA2, "Y", "N" )