Hello I would need someones help please.
I want to combine two different tasks and don't know how.
First I created an row number for each group: Description for Task1
I grouped the table by a station ID.
Now I want to get the value from the previous row: Description for Task2
The problem is that this doesn't work:
I think this comes due to the fakt that the index is not unique.
Because for example the index "1" exists for every ID.
Maybe it's easier to understand when u see the table. I blacked out specific values because they are not important for this.
I would need to only take the index+1 where the index+1 and index have the same ID.
What I want to achive is to get a column which shows me the previous value from beschreibung. But only the previuos value where the ID is the same.
Does anyone know how to solve this?
My guess is that you need to do the lookupvalue task in powerquery. But I don't know how.
Maybe something like this? : Lookup Value
I welcome any help.
Based on your update:
MeasurePrev = var __lastInd = CALCULATE(MAX('Table'[Beschreibung]), FILTER(ALL('Table'), 'Table'[index] = SELECTEDVALUE('Table'[index]) +1 ), VALUES('Table'[ID]))
return __lastInd
CalculatedColumnPrev = var _idx = 'Table'[index] +1
var _NodeId = 'Table'[ID]
return
CALCULATE(max('Table'[Beschreibung]), FILTER(ALL('Table'), ('Table'[index]) = _idx && 'Table'[ID] = _NodeId) )
Related
My co-worker has run into an issue finding the amount of days between 2 different entries on a database.
In this database , there can be multiple entires with the same RegNumber , however sometimes the entries are on separate dates.
We would need to fetch the first date (TxrDate) for each RegNr and add it to the "FirstInvDate" column on each line.
Please see the below sample data:
And the below is what he has tried:
Does anyone know if there is an easier way to do this or a specific formula to follow ?
To create a new table use:
FistInvDate =
var __currRegNumber = 'Table'[RegNumber]
return
calculate( min( table[yourDate]), filter(ALL('table'), __currRegNumber = 'Table'[RegNumber]))
I have the following Table:
BaseTable
It represents processes with a certain category.
And there is also a Date Table over column TIMESTAMP.
I would like to show a Measure based on another Measure that calculates the Date-Difference until the selected Date.
So first this is how I calculate the Date-Difference:
AGE =
VAR SELECTED_DATE = CALCULATE(MAX(DATUM[Date]), ALLSELECTED(DATUM))
VAR STARTDATE_PROCESS = Calculate(MAX(Workflow[MIN_TIMESTAMP]),DATUM[Date]<=MAX(DATUM[Date]), ALL(DATUM[Date]))
RETURN
DATEDIFF(STARTDATE_PROCESS,SELECTED_DATE,DAY)
Now I want to use a Measure which depends on the result of AGE, like
NEW = IF([AGE]<=3,CALCULATE(COUNT(Workflow[PROCESS]),DATUM[Date]<=MAX(DATUM[Date]),ALL(DATUM)))
or
OLD = IF([AGE]>3,CALCULATE(COUNT(Workflow[PROCESS]),DATUM[Date]<=MAX(DATUM[Date]),ALL(DATUM)))
The Measures AGE, OLD and NEW look like that with the Base Table:
Measures
As you can see the aggregation is not working correctly:
Result_Wrong
But it should be like that
Result_Correct
Any idea how to fix that?
Thank you!
So the problem is that the subtotal is calculated at a whole different context, and because your Age measure is based on the MAX(Workflow[MIN_TIMESTAMP]) that won't take into account that there can be multiple processes.
To do what you want, you need to change the New and Old measures to perform an aggregation per process and then return the result of that. Something like this:
New_agg =
VAR tbl = ADDCOLUMNS(CALCULATETABLE(VALUES(Workflow[Process]), ALL('Date')), "age", [Age], "count_process", CALCULATE(COUNT(Workflow[Process]), ALL('Date')))
RETURN SUMX(tbl, IF([age]<=3, [count_process]))
Demo File
Let me know if below solution is working
Unfortunately I am unable to generate the dummy data that you have been using, so Created my own data for developing the solution.
Now from this data I have calculated the difference of dates and put it as Age
Now to get the count of process for the condition like yours, I have created two formulas and the result is:
Logic I followed here is, instead of creating measure I have created columns and took the sum of those columns which will give the data you need as sum of those columns.
Column for New:
New = IF((Sheet1[Age]) > 20, 1,0)
Column for Old:
Old = IF((Sheet1[Age]) < 20, 1,0)
Now place both formulas in "Values" and take sum as the aggregation.
Final result is
I have following table.
I want to find out Distributors and assign code for max date transactions.
so answer will be like this.
MAXDateByDistribuitor :=
VAR CurrentDate = SELECTEDVALUE('Table'[Date of Transaction])
VAR LastDateByDist =
LASTDATE(
CALCULATETABLE(
VALUES('Table'[Date of Transaction]),
ALLEXCEPT('Table','Table'[Distribuitors])))
RETURN
//Filters on this visual
//Show items when the value:
//MAXDateByDistribuitor is 1 | Apply filter
IF(CurrentDate=LastDateByDist,1,0)
Note that when using a single table, the functions will only return values present in that table. It would be advisable to add at least one calendar and one dimension to identify the distributors.
i need your help calculating following:
based on the region and value(left table), i need to calculate the number of minium values displayed.
For instance, Value 5 is the minium value 3 times. Which function allow me to get that, i'm not able to find a right answer for days.
any idea is welcome!
many thanks
See data as example
Use the following DAX measure to achieve your goal:
CountMinValue=
VAR __value = SELECTEDVALUE( 'Table'[Value] )
Return CALCULATE( COUNT( 'Table'[Min Value]), 'Table'[Min Value] = __value )
Using DAX to identify first instance of a record
I'm faced with trying to identify the first instance in a database where someone (identified by the ID column) has purchased a product for the first time. It's possible for said person to purchase the product multiple times on different days, or purchase different products on the same day. I drummed up an excel formula that gets me there, but am having trouble translating into DAX.
=COUNTIFS(ID,ID,PurchaseDate,"<="&PurchaseDate,Product,Product)
Which results in the correct values in the "First Instance?" Column.
Ideally I won't have to hardcode values, as I would like to use the "Product" column as a parameter in the future. If there are other suggests aside from translating this in DAX, that would also be appreciated! (IE using filters, or other tools in PowerBI)
Thanks in advance!
This is very similar to an answer I gave to another question (which you can find here).
In that question, the request was to see a running count of rows for the given row's criteria (product, year, etc.). We can modify that slightly to get it to work in your problem.
This is the formula I provided in the answer I linked above. The basic concept is to use the EARLIER functions to get the value from the row and pass it into the filter statement.
Running Count =
COUNTROWS(
FILTER(
'Data',
[ProductName] = EARLIER([ProductName]) &&
[Customer] = EARLIER([Customer]) &&
[Seller] = EARLIER([Seller]) &&
[Year] <= EARLIER([Year])
)
)
What I would suggest for your problem is to create this as a TRUE/FALSE flag by simply checking if the running count is 1. This formula will evaluate to a Boolean flag.
First Instance =
COUNTROWS(
FILTER(
'Data',
[ID] = EARLIER([ID]) &&
[Product] = EARLIER([Product]) &&
[Purchase Date] <= EARLIER([Purchase Date])
)
) = 1