Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hello! I am having trouble finding the difference in unix time between readings at the same location. Below is an example of a table. The "Time in between readings" is the column I am attempting to create. I highlighted the table in terms of location to emphasize that the difference only needs to be taken if at the same location.
This is the command I have, but it does not work properly. Any suggestions on how to do this?
Time in between readings = IF(ISBLANK(Data[temperature]) = FALSE() && Data[Location = Data[Location], VAR Diff = Data[unix time] - CALCULATE(SUM(Data[unix time]), Filter(Data, Data[Index] = EARLIER(Data[Index]) ) )
return
IF(Diff = VALUE(Data[unix time]), 0, diff))
Solved! Go to Solution.
@xsaldana
Another solution with some help from power query (if applicaple) https://www.dropbox.com/t/Gj8t4ZxelU0zRmqA
Time in between readings =
VAR CurrentIndex = Data[Index]
VAR CurrentTime = Data[unix time]
VAR PreviousTime =
CALCULATE (
VALUES ( Data[unix time] ),
ALLEXCEPT ( Data, Data[Location] ),
Data[Index] = CurrentIndex - 1
)
RETURN
IF (
NOT ISBLANK ( Data[temperature] ) && NOT ISBLANK ( PreviousTime ),
CurrentTime - PreviousTime
)
@xsaldana
Another solution with some help from power query (if applicaple) https://www.dropbox.com/t/Gj8t4ZxelU0zRmqA
Time in between readings =
VAR CurrentIndex = Data[Index]
VAR CurrentTime = Data[unix time]
VAR PreviousTime =
CALCULATE (
VALUES ( Data[unix time] ),
ALLEXCEPT ( Data, Data[Location] ),
Data[Index] = CurrentIndex - 1
)
RETURN
IF (
NOT ISBLANK ( Data[temperature] ) && NOT ISBLANK ( PreviousTime ),
CurrentTime - PreviousTime
)
That worked. Thank you!!
Hi @xsaldana
you may try
Time in between readings =
VAR CurrentTime = Data[unix time]
VAR LocationTable =
CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Location] ) )
VAR PreviousTime =
MAXX (
FILTER (
CurrentTime,
Data[unix time] < CurrentTime
&& Data[temperature] <> BLANK ()
),
Data[unix time]
)
RETURN
IF ( NOT ( ISBLANK ( Data[temperature] ) ), CurrentTime - PreviousTime )
Thank you for suggesting this! Unfortunately, it did not work. It's stuck on "working on it"
@xsaldana
Apparantly this need to be optimized. However, and before going into further complicatios would you please try this
Time in between readings =
VAR CurrentTime = Data[unix time]
VAR LocationTable =
CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Location] ) )
VAR T1 =
FILTER ( CurrentTime, Data[unix time] < CurrentTime )
VAR T2 =
FILTER ( T1, Data[temperature] <> BLANK () )
VAR PreviousTime =
MAXX ( T2, Data[unix time] )
RETURN
IF ( NOT ( ISBLANK ( Data[temperature] ) ), CurrentTime - PreviousTime )
Thank you! It seem this one runs but it doesn't work. The error I get is "The FILTER function expects a table expression for argument", but a string or numeric expression was used.
PowerBI highlights red "CurrentTime" in
VAR T1 = FILTER ( CurrentTime,
My mistake, I copied the wrong variable.
Time in between readings =
VAR CurrentTime = Data[unix time]
VAR LocationTable =
CALCULATETABLE ( Data, ALLEXCEPT ( Data, Data[Location] ) )
VAR T1 =
FILTER ( LocationTable, Data[unix time] < CurrentTime )
VAR T2 =
FILTER ( T1, Data[temperature] <> BLANK () )
VAR PreviousTime =
MAXX ( T2, Data[unix time] )
RETURN
IF ( NOT ( ISBLANK ( Data[temperature] ) ), CurrentTime - PreviousTime )
@xsaldana , New column
new column =
var _max = max(filter(Table, Data[Location] = earlier(Data[Location]) && Data[unix time] < earlier( Data[Location] )),[unix time])
return
IF(not(ISBLANK(Data[temperature])) , Data[temperature] - max(filter(Table, Data[Location] = earlier(Data[Location]) && Data[unix time] =_max ), Data[temperature]) , blank())
Hello, thank you for taking the time to look at this! Unfortunately, I get an error when I use your command. It says "the expression refers to multiple columns. multiple columns cannot be converted to scalar value.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
24 | |
13 | |
11 | |
10 | |
9 |
User | Count |
---|---|
18 | |
14 | |
14 | |
12 | |
11 |