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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
hitesh1607
Advocate II
Advocate II

Creating Calculated Columns

I have 3 columns in the table. (1st row is the header)

COLUMN ACOLUMN B COLUMN C
20D100
30B20
60A60
50D30
25D10
27D10

 

I need to create 5 new calculated columns and get results like this (1st row is header)

A < 30DC < 50A < 30 && D && C < 50A < 30 || D || C < 50
TrueTrue  True
  True True
     
 TrueTrue True
TrueTrueTrueTrueTrue
TrueTrueTrueTrueTrue

 

I am getting a Circular dependency error. Can anyone please help me?

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @hitesh1607,

 

>>I am trying to create a Filter for the user where he can sort a report or visual by clicking options like 'Sales less than 40% or Qty change more than 10%'.

 

Based on your description, I suggest to create a calculated table, and then create a measure for each filter. Since I don't have your sample, I did the following based on my sample.

 

1.Create a calculated table contains COLUMN A ,B,C as your description in your first post.

 

Table =

ADDCOLUMNS (

    SUMMARIZE ( 'Sales OrderDetails', 'Sales OrderDetails'[productid] ),

    "QTY", CALCULATE ( SUM ( 'Sales OrderDetails'[qty] ) ),

    "Salesamonut", 'Sales OrderDetails'[Saleamount]

)

 

2.Create measures for all your filter(To save time I only created three measures):

 

A<30 = IF( MAX('Table'[QTY]) <1000,1,0)

 

Untitled picture1.png

 

3.Create a table for slicer on these measures (How to use measures for slicer, please refer tohttps://www.fourmoo.com/2017/11/21/power-bi-using-a-slicer-to-show-different-measures/😞

 

Untitled picture2.png

 

4.Create a measure for filter on the visual:

Measure =

VAR SELECTEDVALUE =

    SELECTEDVALUE ( Table2[Slicer] )

RETURN

    SWITCH (

        TRUE (),

        SELECTEDVALUE = "A<30", [A<30],

        SELECTEDVALUE = "D", [D],

        SELECTEDVALUE = "C<50", [C<50]

    )

5.Add the measure to the visual level filter:

 

 

Untitled picture3.pngUntitled picture4.png

 

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EU_kkYgRWzVJr3b7nm...

 

Best Regards,

Dedmon Dai

View solution in original post

13 REPLIES 13
v-deddai1-msft
Community Support
Community Support

Hi @hitesh1607,

 

>>I am trying to create a Filter for the user where he can sort a report or visual by clicking options like 'Sales less than 40% or Qty change more than 10%'.

 

Based on your description, I suggest to create a calculated table, and then create a measure for each filter. Since I don't have your sample, I did the following based on my sample.

 

1.Create a calculated table contains COLUMN A ,B,C as your description in your first post.

 

Table =

ADDCOLUMNS (

    SUMMARIZE ( 'Sales OrderDetails', 'Sales OrderDetails'[productid] ),

    "QTY", CALCULATE ( SUM ( 'Sales OrderDetails'[qty] ) ),

    "Salesamonut", 'Sales OrderDetails'[Saleamount]

)

 

2.Create measures for all your filter(To save time I only created three measures):

 

A<30 = IF( MAX('Table'[QTY]) <1000,1,0)

 

Untitled picture1.png

 

3.Create a table for slicer on these measures (How to use measures for slicer, please refer tohttps://www.fourmoo.com/2017/11/21/power-bi-using-a-slicer-to-show-different-measures/😞

 

Untitled picture2.png

 

4.Create a measure for filter on the visual:

Measure =

VAR SELECTEDVALUE =

    SELECTEDVALUE ( Table2[Slicer] )

RETURN

    SWITCH (

        TRUE (),

        SELECTEDVALUE = "A<30", [A<30],

        SELECTEDVALUE = "D", [D],

        SELECTEDVALUE = "C<50", [C<50]

    )

5.Add the measure to the visual level filter:

 

 

Untitled picture3.pngUntitled picture4.png

 

 

For more details, please refer to the pbix file: https://qiuyunus-my.sharepoint.com/:u:/g/personal/pbipro_qiuyunus_onmicrosoft_com/EU_kkYgRWzVJr3b7nm...

 

Best Regards,

Dedmon Dai

edhans
Super User
Super User

Calculated columns should be avoided if at all possible. Push this back into Power Query. Put this code in a Blank Query to see what I did:

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjJQ0lFyAWJDAwOlWJ1oJWOQgBMQG0H4ZiC+IxCbQfimMA3GEL6RKdwACN8ciR8LAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type text) meta [Serialized.Text = true]) in type table [#"COLUMN A" = _t, #"COLUMN B" = _t, #"COLUMN C" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"COLUMN A", Int64.Type}, {"COLUMN B", type text}, {"COLUMN C", Int64.Type}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "A < 30", each [COLUMN A] < 30, type logical),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "D", each [COLUMN B] = "D", type logical),
    #"Added Custom2" = Table.AddColumn(#"Added Custom1", "C < 50", each [COLUMN C] < 50, type logical),
    #"Added Custom3" = Table.AddColumn(#"Added Custom2", "A < 30 && D && C < 50", each [#"A < 30"] and [D] and [#"C < 50"], type logical),
    #"Added Custom4" = Table.AddColumn(#"Added Custom3", "A < 30 || D || C < 50", each [#"A < 30"] or [D] or [#"C < 50"], type logical)
in
    #"Added Custom4"

1) In Power Query, select New Source, then Blank Query
2) On the Home ribbon, select "Advanced Editor" button
3) Remove everything you see, then paste the M code I've given you in that box.
4) Press Done

 

It looks like this when done:

2020-04-10 14_27_42-Untitled - Power Query Editor.png

 

In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables
Creating a Dynamic Date Table in Power Query



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

@edhans - Thanks for explaining this. I should have mentioned the columns in the table Column A and Column B are the measures which were created by me using Variables. I am sorry this is my 1st post. I should have cleared that in the starting only.

FrankAT
Community Champion
Community Champion

Hi @hitesh1607 ,

 

see figure:

 

10-04-_2020_23-12-11.png

 Regards FrankAT

@FrankAT - Hi Frank please check my post reply to Matt. I have explained that Column A and Column B are measures. Sorry for the misunderstanding. 

MattAllington
Community Champion
Community Champion

Power BI is different to Excel. Generally speaking you should avoid calculated columns. There are exceptions, but mostly they are not the answer. https://exceleratorbi.com.au/calculated-columns-vs-measures-dax/

What are you trying to acheive here?  What are you going to do with this new information?  If you do need the columns, you can create conditional columns in Power Query. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

I am trying to create a Filter for the user where he can sort a report or visual by clicking options like 'Sales less than 40% or Qty change more than 10%'.
I have done that using bookmarks but I was finding a way to do that using calculate columns.

I am sorry I might be doing it wrong. I am trying to learn the best way.

OK, so columns are the correct approach for this.  But what is the data in each column, and how is it related to the filters you want to apply?  What is the data in A and C?  What is the data in B?



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

@MattAllington - Sure.

 

The first column is Sales which is a measure I created.

The second column is in product table telling the Priority

The third column is the Qty measure which is created

 

This is the First calculated column that I am trying to create.

A < 30 =
 
VAR ColumnA=
CALCULATE (
SUMX(Sales,Sales[Sales]),
'Calendar'[Relative Quarter] IN {-1,-2,-3,-4},
USERELATIONSHIP ('Calendar'[DateKey], Sales[ShipDateKey] )
) -- This is the calculated measure 1
 
VAR Column B = Product 'Priority -- This one is the Column which exists in the table already

VAR ColumnC =
CALCULATE (
SUMX(Sales,Sales[Quantity]),
'Calendar'[Relative Quarter] IN {-5,-6,-7,-8},
USERELATIONSHIP ('Calendar'[DateKey], Sales[ShipDateKey] )
) -- This is the calculated measure  

RETURN if (ColumnA < 30, "A<30" , "Others")

I was able to create the 1st calculated column and was getting the correct results. This is the Second calculated column that I am trying to create.
 
A < 30 || B = "D" || C< 50 =
VAR ColumnA=
CALCULATE (
SUMX(Sales,Sales[Quantity]),
'Calendar'[Relative Quarter] IN {-1,-2,-3,-4},
USERELATIONSHIP ('Calendar'[DateKey], Sales[ShipDateKey] )
 
VAR ColumnB = Table'ColumnB

VAR ColumnC =
CALCULATE (
SUMX(Sales,Sales[Quantity]),
'Calendar'[Relative Quarter] IN {-5,-6,-7,-8},
USERELATIONSHIP ('Calendar'[DateKey], Sales[ShipDateKey] )
) -- This is the calculated measure 3 

RETURN if (ColumnA < 30 || ColumnB = "D" || ColumnC < 50 ,"Any Scenario" , "Others")
 
When I click on this to create 2nd calculated column I get Circular dependency error.
 

Please post an image of your data model view. 

so are you trying to allow users to filter products in bands for each product priority?



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

@MattAllington - I want to provide flexibility to users so that they can see the visuals by using a slicer option. That slicer will be based on Sales less than > 50 or Qty less than 30.

 

In my model

I have 4 tables. 

Product (where the Product'Priority' = A,B,C or D) option

Date table

Sales table and is joined with Product and date on keys

and last is Measure Table which holds all the measures. Measure A(Sales) and Measure C(qty) are in there. 

Those measures are calculated like this

CALCULATE (
SUM(Sales[Quantity]),
'Calendar'[Relative Quarter] IN {-1,-2,-3,-4},
USERELATIONSHIP ('Calendar'[DateKey], Sales[ShipDateKey] )
)

 

Thank you for being patient.

 

Regards

Hitesh

 

Hi,

I think this question can be solved with measures.  Share the link from where i can download your PBI file - you may share the 3 raw data tables in that PBI file.  Please also share 2 additional tables - one for showing the sales buckets and other for quantity buckets.  The sales bucket table (as also the quantity bucket table) should have 3 columns - Lower, Upper and Segment.  For e.g.

Lower      Upper          Segment

0              50                0-50

51            75                51-75

I'll try to solve it with measures only.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

@hitesh1607 calculated columns have to be created in tables. If your "column A' is a measure then it isn't in a table to add new columns to.

 

How to get good help fast. Help us help you.
How to Get Your Question Answered Quickly
How to provide sample data in the Power BI Forum



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.