The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
I have 3 columns in the table. (1st row is the header)
COLUMN A | COLUMN B | COLUMN C |
20 | D | 100 |
30 | B | 20 |
60 | A | 60 |
50 | D | 30 |
25 | D | 10 |
27 | D | 10 |
I need to create 5 new calculated columns and get results like this (1st row is header)
A < 30 | D | C < 50 | A < 30 && D && C < 50 | A < 30 || D || C < 50 |
True | True | True | ||
True | True | |||
True | True | True | ||
True | True | True | True | True |
True | True | True | True | True |
I am getting a Circular dependency error. Can anyone please help me?
Solved! Go to Solution.
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)
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/😞
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:
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
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)
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/😞
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:
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
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:
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
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 - Hi Frank please check my post reply to Matt. I have explained that Column A and Column B are measures. Sorry for the misunderstanding.
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.
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?
@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.
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?
@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
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.
@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
DAX is for Analysis. Power Query is for Data Modeling
Proud to be a Super User!
MCSA: BI ReportingUser | Count |
---|---|
69 | |
65 | |
63 | |
55 | |
28 |
User | Count |
---|---|
112 | |
81 | |
65 | |
48 | |
42 |