Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
aj1107
Helper I
Helper I

calculated column logic.

I need to create a calculated column based on below condition. Not sure how to get the entire planid logic using calc column.

i tried to create a calctable of below condition and then update using planid=related(planid). Is there a way to get it without calctable.

 

condition:

if cdate<=Monthlydate and st="open"  then update 1 for the entire planid (all 3 rows of planid=1)

 

id,cdate,Monthlydate,st, calccolumn

1,01/13/2017,01/31/2017,open,1

1,01/13/2017,02/28/2017,closed,1

1,01/13/2017,03/31/2017,closed,1

4,01/13/2017,04/30/2017,closed,0

 

Thank you.

2 ACCEPTED SOLUTIONS

Hey,

 

you can find a little example

 

For this table:

table.png

 

A caclculated column using this DAX statement:

calcColumn = 
if(
    calculate(
        count('Table1'[id]),
        FILTER(
            ALLEXCEPT('Table1',Table1[id]),
            'Table1'[right] > 'Table1'[left] && 'Table1'[literal] = "yes"
        )
   ) >= 1, 
   1, 
   2
)

Returns these values:

table - result.png 

 

Hope this helps

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

@aj1107,

 

You may refer to the following DAX as well.

calccolumn =
IF (
    COUNTROWS (
        FILTER (
            Table1,
            Table1[id] = EARLIER ( Table1[id] )
                && Table1[cdate] <= Table1[Monthlydate]
                && Table1[st] = "open"
        )
    )
        > 0,
    1,
    0
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
TomMartens
Super User
Super User

Hey,

 

just for my understanding, i try to rephrase your requirement

 

  • even if row 2 and 3 do not satisfy the condition st = open, the value for the calculated column is 1 because row 1 satisfies this condition
  • if one row of a group (grouped by id) satisfies the condition, the value for all rows in the group becomes 1

Is my understanding correct?

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

yes. if atleast one row of a group(id) satisfies then the entire group id (planid=1) is 1.

@aj1107,

 

You may refer to the following DAX as well.

calccolumn =
IF (
    COUNTROWS (
        FILTER (
            Table1,
            Table1[id] = EARLIER ( Table1[id] )
                && Table1[cdate] <= Table1[Monthlydate]
                && Table1[st] = "open"
        )
    )
        > 0,
    1,
    0
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hey,

 

you can find a little example

 

For this table:

table.png

 

A caclculated column using this DAX statement:

calcColumn = 
if(
    calculate(
        count('Table1'[id]),
        FILTER(
            ALLEXCEPT('Table1',Table1[id]),
            'Table1'[right] > 'Table1'[left] && 'Table1'[literal] = "yes"
        )
   ) >= 1, 
   1, 
   2
)

Returns these values:

table - result.png 

 

Hope this helps

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.