I have a data set that contains duplicates and i am trying to do the equivalent of a Vlookup from excel. In excel when you use the vlookup function it will just return the first value even if there is a duplicate. The data set that i am working with has a unique 16 character string.
I have utilized some videos, forms, and other resources but no luck. I have used the calculation equation with a first non blank and a filter but i either get an error or returns blank.
https://1drv.ms/x/s!AtrxZbQBYb0LjZtaIkZcn4qsMimwnQ?e=PZbNud
Column = CALCULATE(
FIRSTNONBLANK('Table1'[ID]),
FILTER('Table1','Table1'[Parent]='Table1'[ID]))
You can go with:
Column =
var SampleID = 'Sample Data'[ID]
var EarliestDate = CALCULATE(MIN('Sample Data'[Creation Date]);FILTER('Sample Data';'Sample Data'[Parent] = SampleID))
return CALCULATE(MIN('Sample Data'[Text]);FILTER('Sample Data';'Sample Data'[Parent] = SampleID && 'Sample Data'[Creation Date] = EarliestDate))
Note: it finds the earliest date ann when dates are equal, smallest string
Enjoy!
Related
I have a database table that contains records, where each record has a criteria attribute. This criteria attribute can hold anywhere between 1-n criteria that I'd like to apply as filters on a different table.
This looks something like:
message.status:::eq:::submitted;;;message.count:::ge:::5
but could also be only
message.count:::ge:::5
What I'd like to do in DAX, is take that string and translate it into dynamic Filter attributes. So I somehow need to split the string based on ;;;, and then disect each section into the target (e.g. message[count]), the operator (e.g. ge --> >=) and the value (e.g. 5).
So in the end the following DAX snippet should be added to my Calculate 1 or more times:
example measure = CALCULATE(
COUNTROWS('message),
FILTER (
ALL('message'),
--- line below should be dynamically injected
message[count] >= 5
),
I'm struggling with how to create a loop (is this even possible in PBI?), and then even with a single string... hoe to filter based on this.
Thanks
You can try to build new table for splited message.
Table 2 =
var _splitby = ";;;"
var _string = SELECTCOLUMNS(ADDCOLUMNS(VALUES('Table'[message]),"pathx", SUBSTITUTE([message],_splitby,"|")),"pathx",[pathx])
var _generate = GENERATE(_string, GENERATESERIES(1, PATHLENGTH([pathx])))
var _GetVal = SELECTCOLUMNS(_generate, "Msg", PATHITEM([pathx], [Value]))
return
_GetVal
If you have always message.count:::ge::: like string at the end, you can follow these steps in Power Query-
Step 1: Duplicate you message column
Step-2: apply split on new duplicated column using string message.count:::ge::: and you will have a new column with last Numeric value from your original text.
Step-3: you can now apply filter on the new column.
Sample Output-
Here is my sample table (for this report I'm using only one table, so there is no table-relationship-links to contend with):
Cost Centre
Project
Invoice Approver
123
AB
Person One
123
AB
Person Two
123
ZZ
Person One
456
TB
Person Three
I have a measure already written Approver = COUNT('Table'[Invoice Approver]). In the sample above, Approver = 4.
I have created a new table showing only those combinations with 1 approver. The table shows 123|ZZ and 456|TB (NOTE: for this table, the approver(s) do not need to be shown, only the unique cost centre/project combinations).
My next step is to have a Card showing the net quantity of the filters: 2. But I need help in writing the DAX measure.
I have tried the following DAX formulae:
Code
Result
1InvApp = COUNTROWS(FILTER('Table',[Approver]="1"))
"DAX comparison operations do not support comparing values of type Integer with values of type Text."
1InvApp = COUNTROWS(FILTER('Table',[Approver]=1))
Blank (text)
1InvApp = CALCULATE(COUNTROWS('Table'),[Approver]="1")
"A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression."
1InvApp = CALCULATE(COUNTROWS('Table'),[Approver]=1)
"A function 'CALCULATE' has been used in a True/False expression that is used as a table filter expression."
1InvApp = COUNTX('Table',[Approver]="1")
"DAX comparison operations do not support comparing values of type Integer with values of type Text."
1InvApp = COUNTX('Table',[Approver]=1)
"The function COUNTX cannot work with values of type Boolean."
1InvApp = COUNTAX(FILTER('Table',[Approver]=1),'Table'[Approver])
Blank (text)
1InvApp = COUNTAX(FILTER('Table',[Approver]="1"),'Table'[Approver])
"DAX comparison operations do not support comparing values of type Integer with values of type Text."
1InvApp = COUNTROWS(FILTER(ALL('Table'),[Approver]=1)) (as suggested here)
Blank (text)
QUESTION: What is the correct DAX syntax to show the desired total result, 2?
Thanks in advance.
You can do this in two steps:
First:
Measure = CALCULATE(COUNT('Table'[Invoiced]), FILTER(ALL('Table'), SELECTEDVALUE('Table'[Cost Centre]) = 'Table'[Cost Centre] && 'Table'[Project] = SELECTEDVALUE('Table'[Project])))
Secod:
OnlyOne = CALCULATE(COUNTROWS(CALCULATETABLE('Table', FILTER('Table', var __xx = [Measure] return [Measure] = 1))))
How can I filter in the table only the lines where the values of "Conversion Time"> "Upper Limit Express Conv"
Since "Upper Limit Express Express" is a variable that is adjusted with Date slicer
This way it worked
Filter Column =
VAR Conversion Time = SELECTEDVALUE(Autentique[Conversion Time])
Return
IF(SELECTEDVALUE(Conversion Time)>[Limite Superior Conversão];"A";"B")
You could use a filter column to do this:
Filter Column =
VAR UpperLimit = [Upper Limit Express Conv]
RETURN IF([Conversion Time]>UpperLimit,1,0)
Once the column is created you can simply use it in the filter pane and filter for either 1 or 0 depending on your needs. Hope this helps.
Edit:
Since the column [Conversion Time] is also not readily available, you can try passing that into a variable:
Filter Column =
VAR UpperLimit = [Upper Limit Express Conv]
VAR ConvTime = DATEDIFF([Activities.Novo],[Signed_At],DAY)
RETURN IF(ConvTime>UpperLimit,1,0)
I have three column one is Id(ID is same) 2nd col is amount and third is date, I want difference between two rows(amount)
As you want to have the previous value of the date where the ID is equal, you can use the following:
Add a column,
Column4 =
var baseFilter = FILTER(DiffRows;DiffRows[Column1] = EARLIER(DiffRows[Column1]))
var selectDate = CALCULATE(LASTDATE(DiffRows[Column3]);baseFilter;
FILTER(baseFilter; DiffRows[Column3] < EARLIER(DiffRows[Column3])))
return
DiffRows[Column2] - CALCULATE(sum(DiffRows[Column2]);baseFilter;
FILTER(baseFilter; DiffRows[Column3] =selectDate))
First I create a basefilter to ensure the IDs are same.
Next I select the date whcih is the previousdate within the set of same ids
Last I use this date, to filter the correct value out of the rows.
End result:
Power BI Desktop, DAX
I need to help build a control column that finds a bug.
I have three columns: "SN" - serien nr. Data type: text, "MTH" Type data: Whole Number and "Date" Data type: Date.
Each SN has x Mth. Every Mth has just one date.
For each SN, it is true that it can not have more Mth at an earlier date.
Example:
I solved it only by counting the help tables in Query Editor, which took a lot of performance.
I was able to achieve this using the following calculated column:
Control =
VAR BugSN = Bug[SN]
VAR BugMth = Bug[Mth]
VAR BugDate = Bug[Date]
RETURN CALCULATE(
MAX(Bug[Date]),
ALL(Bug), Bug[SN] = BugSN, Bug[Mth] = BugMth
) = BugDate
What this says is that if the date in that row is the max for that SN and Mth combination, then TRUE otherwise FALSE.
(I named the table Bug, but you'll need to replace that with whatever your table name is.)