I have a table below:
I am trying to get the average of "someNumber" (which is number of seconds) per date and then convert that number into miutes and seconds.
So, I am drawing the graph below:
As you can see, I used the average filter and it calculated the average of "someNumber" per date. For instance, the average on 1st is 13. Now, how do I convert 13 into minutes and seconds so that I can display it as a tooltip?
Create a measure to get the average in seconds.
avg = AVERAGE(Table[SomeNumber])
Then create a measure for the tooltip lets call it Time, this helpful measure was created by #konstantinos and #smoupre in the Power BI community blog.
Time =
VAR Duration = [avg] // Here use the average measure created before
VAR Hours =
INT ( Duration / 3600)
VAR Minutes =
INT ( MOD( Duration - ( Hours * 3600 ),3600 ) / 60)
VAR Seconds =
ROUNDUP(MOD ( MOD( Duration - ( Hours * 3600 ),3600 ), 60 ),0)
VAR H =
IF ( LEN ( Hours ) = 1,
CONCATENATE ( "0", Hours ),
CONCATENATE ( "", Hours )
)
VAR M =
IF (
LEN ( Minutes ) = 1,
CONCATENATE ( "0", Minutes ),
CONCATENATE ( "", Minutes )
)
VAR S =
IF (
LEN ( Seconds ) = 1,
CONCATENATE ( "0", Seconds ),
CONCATENATE ( "", Seconds )
)
RETURN
CONCATENATE ( M, CONCATENATE ( ":", S ) )
Now use the [Time] measure as tooltip in your chart
Hope it helps.
Related
I have a code in a powerbi table that displays all. It basically counts how long a particular task is performed for mgt. It was done by someone else. I am trying to find out how to get the rows to display a 'No Data' or 'NA' if there is no data. I tried several approaches but could not get it to work. Any suggestions? Linda from Wisconsin.
TimeTaken =
//----CALCULATIONS
VAR DIFF = 'Opened'[Resolved] - 'Opened'[Opened]
VAR NumOfMinutes = DIFF * 24
* 60
VAR DAYS =
IF ( DIFF >= 1, INT ( DIFF ), BLANK () )
VAR HOURS =
INT ( ( DIFF - DAYS ) * 24 )
VAR MINUTES = NumOfMinutes
- ( DAYS * 24
* 60 )
- ( HOURS * 60 )
//---TEXTS
VAR DaysText =
IF ( DAYS >= 1, FORMAT ( DAYS, "00" ) & "days" )
//ELSE ("No Data") >>>>> this not working.. I deleted some
VAR HoursText =
FORMAT ( HOURS, "00" ) & "hrs"
VAR MinutesText =
FORMAT ( MINUTES, "00" ) & "mins"
RETURN
COMBINEVALUES ( " ", DaysText, HoursText, MinutesText )
Hi You can try below code. Just replace your last two line with this code.
RETURN
IF (
ISBLANK ( DaysText ) && ISBLANK ( HoursText )
&& ISBLANK ( MinutesText ),
"NA",
COMBINEVALUES ( " ", DaysText, HoursText, MinutesText )
)
I have the following DAX:
(sum(usage[session_duration])/100)/sum(usage[engaged_sessions])
The problem I have is it returns depending on the filters 2.49, when it should be returning 4.09. 4 for the number of minutes, and 9 for the seconds.
I wrote the following:
Var FirstTotal = (sum(usage[session_duration])/100)/sum(usage[engaged_sessions])
Var SecondTotal = FirstTotal*100
Var ThirdTotal = SecondTotal/60
VAR WholeNumberThirdTotal = INT(ThirdTotal)
Var FirstDot = FIND(".",ThirdTotal,1,0)
Var FourthTotal = MID(ThirdTotal, FirstDot, 2)
Var FifthTotal = FourthTotal*60
RETURN WholeNumberThirdTotal & "." & FifthTotal
and this seems to return the correct results. The problem I have with the above though is that I can't use it within a graph with a Date field. It only works within a Card.
Anyone know how I can improve this?
It appears to me the following returns a value in units of seconds:
SUM ( usage[session_duration] ) / SUM ( usage[engaged_sessions] )
I.e., without the /100 you have 249s, which is the same as 4m + 9s.
You can add formatting to this to get the display you're after:
VAR Sec = SUM ( usage[session_duration] ) / SUM ( usage[engaged_sessions] )
RETURN
FORMAT ( INT ( Sec / 60 ), "0" ) & "." & FORMAT ( MOD ( Sec, 60 ), "00" )
As you point out, this is a text value so it can't be used as a numerical value in chart visuals. You can convert 249 into the decimal value 4.09 just as easily:
VAR Sec = SUM ( usage[session_duration] ) / SUM ( usage[engaged_sessions] )
RETURN
INT ( Sec / 60 ) + MOD ( Sec, 60 ) / 100
If you use this in a bar chart, the height of the bars will be proportional to 4.09 minutes (i.e. 4m + 5.4s) rather than 4m + 9s (4.15 m).
Since Power BI doesn't have a duration type available for measures, if you're using a single measure, you must either sacrifice some accuracy in charting or not show the labels on the chart in the format you prefer. If you don't need to show labels on your graph, you can just use Sec / 60 for the graph and the formatted version wherever the numbers are displayed.
I am using this formula to Convert Seconds into D:H:M:S but if its blank or 0 i would like the ::: to not show up. any help would be appreciated.
2. String AVG Duration =
var vSeconds=[1. Time Lapse Sec M AVG]
var vMinutes=int( vSeconds/60)
var vRemainingSeconds=MOD(vSeconds, 60)
var vHours=INT(vMinutes/60)
var vRemainingMinutes=MOD(vMinutes,60)
var vDays=INT(vHours/24)
var vRemainingHours=MOD(vHours,24)
return
vDays&":" &
vRemainingHours&":"&
vRemainingMinutes&":"&
vRemainingSeconds& ""
Image
... Return
if ( isblank ([1. Time Lapse Sec M AVG]) || [1. Time Lapse Sec M AVG] = 0
, blank (), vdays&":"&vRemainghours...
You can simplify this quite a bit with FORMAT.
2. String AVG Duration =
VAR seconds = [1. Time Lapse Sec M AVG]
VAR days = INT ( seconds / 86400 )
VAR partial = seconds / 86400 - days
RETURN
IF (
NOT ISBLANK ( seconds ),
FORMAT ( days, "0:" ) & FORMAT ( partial, "hh:nn:ss" )
)
I am trying to do log(ssrs execution log) analysis is powerbi. Requirement here is to show how many minutes utilized for a particular hour based on the request start & end time. Below is example for 4 requests Start & end time with expected result.
1st request 12:00 AM - 12:15 AM
2nd request 12:05 AM - 12:10 AM
3rd request 12:40 AM - 12:42 AM
4th request 12:41 AM - 12:48 AM
So total minute utilization for 12 AM hour should be 15mins(as first two requests overlap with each other) + 8mins (as last two also overlap for some mins) = 23 mins of total utilization at 12 AM.
Any help will be greatly appreciated.
I'd recommend splitting up the hour into 60 minutes and counting how many of the minutes are within the time frame of one of the requests.
Something like this logic for a calculated column:
Utilization =
VAR CurrentHour = HOUR ( Requests[Start] )
VAR Minutes =
GENERATESERIES (
TIME ( CurrentHour, 0, 0 ),
TIME ( CurrentHour + 1, 0, 0 ),
TIME ( 0, 1, 0 )
) /*This generates a column named [Value] with 61 rows
starting from the beginning of the hour.*/
RETURN
SUMX (
Minutes,
IF (
COUNTROWS (
FILTER (
Requests,
HOUR ( Requests[Start] ) = CurrentHour
&& Requests[Start] < [Value]
&& Requests[End] > [Value]
)
) > 0,
1,
0
)
)
I want to display percentage increase or decrease in total for each month as I select each month i.e when I click on FEB, it should tell me whether there was a percentage increase/decrease in expenses compared to JAN.
I have tried different codes but keep getting an error message.
Here is a DAX CODE I tried:
change perc =
VAR ValueLastMONTH =
CALCULATE (
SUM ( population[TOTAL] ),
FILTER (
population,
population[MONTH]
= ( EARLIER ( population[MONTH] ) - 1 )
&& population[CATEGORY] = EARLIER ( population[CATEGORY] )
)
)
RETURN
IF (
ISBLANK ( ValueLastMONTH ),
0,
( population[TOTAL] - ValueLastMONTH )
/ ValueLastMONTH
I want a new column created to display the percentage increase or decrease from a month to its previous month.
Here is a screenshot of the excel document:
The Column 'Month' is not of type date. How would PowerBi know the text APR represents April? You need to make this column a date.
Now you need to change the script to work with DateDiff:
change perc =
VAR ValueLastMONTH =
CALCULATE (
SUM ( population[TOTAL] ),
FILTER (
population,
DATEDIFF(population[MONTH], EARLIER ( population[MONTH] ),MONTH) = 1
&& population[CATEGORY] = EARLIER ( population[CATEGORY] )
)
)
RETURN
IF (
ISBLANK ( ValueLastMONTH );
0;
( population[TOTAL] - ValueLastMONTH )
/ ValueLastMONTH)