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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Sharkybu
Helper II
Helper II

Dax- Creating a new text column based on calculates values of 2 other columns

Hello everyone and thank you in advance.
I have a table that consists of three columns - here is an example

Source IDTableRow Status
1testopen
1testclosed
1prodclosed
2testclosed
2prodclosed
3testopen


I want to compare the progress between the "test table" to "prod table".
So i'm trying to do a few things:

First give each 'Table' only one value in the row status; either closed or open (if it has both, it's considered open) 
Then I want to compare the the two 'Tables'  and create a new column showing the progress - cause if test is open and prod is closed then the progress is "new project", if test is closed and prod is closed then progress is "Available" and if there is only an open test then progress is  "new worker" 

When I built it in power query I used GroupBy and list.sort and list.distinct to create the values I wanted.
Which come out 5 values (prodopen;testclosed = re opened project // prodopen;testopen = Active // prodclosed;testopen = new project // prodclosed;testclosed = available for project // testopen = new researcher)

The database is already large so I'm trying to built the calculations in DAX to make it run faster.

I tried doing the same in DAX with the following code :

Researcher status =

Var filterHRFull= CALCULATETABLE(HRfull, ALLEXCEPT(HRfull,HRfull[Source ID]))

Var StatPerTable = IF(CALCULATE(DISTINCTCOUNT(HRfull[Row status]), ALLEXCEPT(HRfull,HRfull[Source ID],HRfull[Table]))=1, HRfull[Row status], "Open")

VAR StatAndTable = HRfull[Table] & StatPerTable

Var Combined =  CONCATENATEX(filterHRFull, StatAndTable, ";")

RETURN

IF(Combined = "testOpen" , "New resrarcher",....)
 But the result I'm getting contains duplicates: Source ID 1 gets the value testopen;testopen;prodclosed
Thank you.

1 ACCEPTED SOLUTION
rajendraongole1
Super User
Super User

Hi @Sharkybu - you can create a Calculated Column for Consolidated for status

 

Consolidated Status =
IF(
COUNTROWS(FILTER(HRfull, HRfull[Source ID] = EARLIER(HRfull[Source ID]) && HRfull[Table] = EARLIER(HRfull[Table]) && HRfull[Row Status] = "open")) > 0,
"open",
"closed"
)

 

Create another calculated column for the combined status of test and prod

 

Combined Status =
VAR TestStatus = MAXX(FILTER(HRfull, HRfull[Source ID] = EARLIER(HRfull[Source ID]) && HRfull[Table] = "test"), HRfull[Consolidated Status])
VAR ProdStatus = MAXX(FILTER(HRfull, HRfull[Source ID] = EARLIER(HRfull[Source ID]) && HRfull[Table] = "prod"), HRfull[Consolidated Status])
RETURN
CONCATENATE(TestStatus, ";") & ProdStatus

 

create another calculated column for the progress classification using switch:

Progress =
SWITCH(
[Combined Status],
"open;open", "Active",
"closed;open", "Reopened project",
"open;closed", "New project",
"closed;closed", "Available for project",
"open;", "New researcher",
BLANK()
)

 

Hope this approach avoids duplicates and calculates progress dynamically in your Power BI report





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





View solution in original post

2 REPLIES 2
rajendraongole1
Super User
Super User

Hi @Sharkybu - you can create a Calculated Column for Consolidated for status

 

Consolidated Status =
IF(
COUNTROWS(FILTER(HRfull, HRfull[Source ID] = EARLIER(HRfull[Source ID]) && HRfull[Table] = EARLIER(HRfull[Table]) && HRfull[Row Status] = "open")) > 0,
"open",
"closed"
)

 

Create another calculated column for the combined status of test and prod

 

Combined Status =
VAR TestStatus = MAXX(FILTER(HRfull, HRfull[Source ID] = EARLIER(HRfull[Source ID]) && HRfull[Table] = "test"), HRfull[Consolidated Status])
VAR ProdStatus = MAXX(FILTER(HRfull, HRfull[Source ID] = EARLIER(HRfull[Source ID]) && HRfull[Table] = "prod"), HRfull[Consolidated Status])
RETURN
CONCATENATE(TestStatus, ";") & ProdStatus

 

create another calculated column for the progress classification using switch:

Progress =
SWITCH(
[Combined Status],
"open;open", "Active",
"closed;open", "Reopened project",
"open;closed", "New project",
"closed;closed", "Available for project",
"open;", "New researcher",
BLANK()
)

 

Hope this approach avoids duplicates and calculates progress dynamically in your Power BI report





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Thank you, that is exactly what I was trying to get.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.