I have a column "answers" in my data whose values can be a,b,c up to the letter z. I want to create a "conditional" column that would always result in 1 when the row result equals my list of correct answers ={a,d,f,g,j). I did it with the switch, but as this list can change, adding more letters, it is not automatic, being necessary for me to manually insert each letter that represents the answer into the switch. Is it possible to use a "for" inside power BI so that it automates this?
thought about:
list={a,d,f,g,j)
For k in list:
if responses [k]=list:
1;
else:0
I don't know how to structure this in the context of Dax or M language
Related
Hopefully this is a simple ask but I couldn't figure out how to find it on here.
I have data like this in Power Bi/Power Query:
There's repeated rows/instances for a few of the people in my data. But anytime there's a repeated row for that person, their name does not get repeated. Luckily, I can tell its the same person because of the record_id column.
My simple question is: Can I quickly have Power Bi fill in the blanks? I.e. if record_id L1 is clearly "Erin" --- becauses thats what the first row of it was, can I have it fill in the rest of the missing L1 rows with "erin"?
There is a fill down operation in Power Query that looks like it will do what you want. Just be aware how your data is sorted before you fill. https://learn.microsoft.com/en-us/power-query/fill-values-column
I am a newbie in PowerBi and I am trying to create a DAX in order to compare a column with different variables in order to attribute some values in order to do some conditional formatting of the cells.
I read that I must had a MIN(), MAX(), ... in the expression but I just want to compare for each value not with the maximum.
Thanks in advance for your help and your time
I have a table that contains 3 columns (index, Value, Running total of value). I want to create or populate column/measure (let say called Replaced Value) in such a way that it checks whether Running Total value exceeds a certain threshold (let say 150), then it checks 48 past values of the column named 'Value' and sees if the value is greater than 10 then put 10 in new column otherwise copy the same value of 'Value' column into Replaced Value column. Here is how the structure of the table looks like:
Could anyone guide me how can we do in power BI
You could have used Rolling sum but since you don't have date reference you will need to follow solution provided in https://community.powerbi.com/t5/Desktop/Need-help-SUM-or-AVERAGE-last-7-Previous-Records-Not-Using-Date/td-p/505276
Let me know if you need further help.
Hello M language masters!
I have a question about working with grouped rows when the Power Query creates a table with data. But maybe it is better to start from the beginning.
Important information! I will be asking for example only about adding an index. I know that there are different possibilities to reach such a result. But for this question, I need an answer about the possibility to work on tables. I want to use this answer in different actions (e.g table sorting, adding columns in group table).
In my sample data source, I have a list of fake transactions. I want to add an index for each Salesman, to count operations for each of them.
Sample Data
So I just added this file as a data source in Power BI. In Power query, I have grouped rows according to name. This step created form me column contained a table for each Salesman, which stores all his or her operations.
Grouping result
And now, I want to add an index column in each table. I know, that this is possible by adding a new column to the main table, which will be store a new table with added index:
Custom column function
And in each table, I have Indexed. That is good. But I have an extra column now (one with the table without index, and one with a table with index).
Result - a little bit messy
So I want to ask if there is any possibility to add such an index directly to the table in column Operations, without creating the additional column. My approach seems to be a bit messy and I want to find something cleaner. Does anyone know a smart solution for that?
Thank you in advance.
Artur
Sure, you may do it inside Table.Group function:
= Table.Group(Source, {"Salesman"}, {"Operations", each Table.AddIndexColumn(_, "i", 1, 1)})
P.S. To add existing index column to nested table use this code:
= Table.ReplaceValue(PreviousStep,each [index],0,(a,b,c)=>Table.AddColumn(a,"index", each b),{"Operations"})
I have an Entity column with one row per entity. This table has three columns: Entity ID, a Descriptor, and a Metric. The Descriptor is a concatenation of numerous codes and I would like to see the metrics broken down by code.
I originally just split the Descriptor column into numerous rows but that led to some data relationship issues so I'd like to do it without splitting the Descriptor column.
I tried doing the following DAX formula but it resulted in an error stating "the expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression"
Desired Output Metric = CALCULATE('Metric',CONTAINSSTRING('Entity Table'[Descriptor],'Code Table'[Code]))
Ultimately I'm not even sure I need this as a column, and it may be better as a measure...
Any help would be appreciated. Thank you!
You can get around "the expression contains multiple columns, but only a single column can be used in a True/False expression that is used as a table filter expression" by using Filter within your CALCULATE.
Here it is as a created column. I used an IF because 'E' code evaluates to a blank and you wanted a 0.
Desired Output Metric = IF(CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],'Code Table'[Code])))>0,CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],'Code Table'[Code]))),0)
Here it is as a measure. Be careful to only use this at the Code detail level. When making a measure you need to use aggregate functions to reference your columns, so I am just doing the MIN(Code) since for any single code the Min() will always evaluate to equal that Code. If you try to use this at a higher summary level you may get some odd answers as it will only total for the MIN() code in the data set you are referencing.
Desired Output Metric = IF(CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],MIN('Code Table'[Code]))))>0,CALCULATE(SUM('Entity Table'[Metric]),FILTER('Entity Table',CONTAINSSTRING('Entity Table'[Descriptor],MIN('Code Table'[Code])))),0)