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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Streeph
Frequent Visitor

Use column value in new column formula

I have a source table (IVS_DATA) with a lot of columns, each holding boolean values (TRUE, FALSE or null). Column headers are 3-digit reason codes (e.g. '209').

 

Now, I want to create a new table in which the total 'TRUE' count for all reasons is calculated. My screenshot shows a first attempt: a static column 'Reason' (representing the reason codes) and a a calculated column for the total per reason code.

 

In this example the total of 'TRUE' values for the '209' reason is calculated. Is there a way to replace the statical "209" in the column formula with the value in the preceeding column? Or is there another way I should create this column or table?   

 

Totals per Reason Code.jpg

5 REPLIES 5
Streeph
Frequent Visitor

@Greg_Deckler That would make my source table explode. My source table easily contains many hundredthousands records, and there are about 20 reason colums for each record ... 

Anonymous
Not applicable

Hi @Streeph ,

 

According to your statement, I think the column amount like 209 in IVS_DATA table should be the same as the row amount of the data in Reason column.

As mentioned as above, the calculation in Power BI is based on columns. So it is better you to transform your data by UNPIVOT function to make IVS_DATA contain [REASON] column and [Status] column.

If there are too many data in your table and this function will explode your table into too many rows, you can do some optimazation on your table.

For reference: Optimization guide for Power BI - Power BI | Microsoft Learn

 

Best Regards,
Rico Zhou

 

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

 

Hi @Anonymous, I tried unpivoting, but (apart from a huge multiplication of rows) that also lead to duplicating the unique identifiers in my source table...

 

Before unpivot

 Reason_1Reason_2Reason_3
ID1TRUEFALSEFALSE
ID2FALSETRUETRUE
ID3FALSETRUEFALSE

 

After unpivot:

 ReasonValue
ID1Reason_1TRUE
ID1Reason_1FALSE
ID1Reason_1FALSE
ID2Reason_2FALSE
ID2Reason_2TRUE
ID2Reason_2TRUE
ID3REason_3FALSE
ID3REason_3TRUE
ID3REason_3FALSE

 

FREDPI
Frequent Visitor

I think you will need to transpose the (IVS_DATA) Tabel in Power Query.
So you can get a a table with 2 columns.

  1. Reason Code 
  2. Status (true,false,blank)

Then you can create a measure that calculates the number of times TRUE is happening for a specifiek reason code.

Greg_Deckler
Community Champion
Community Champion

@Streeph Typically you would unpivot the TRUE/FALSE columns, put Reason in a table and create a measure that calculates the count.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors