I have this table with only start time of every task. What I want to do is to calculate for every user his starting time (doesn't matter what task) and end time (doesn't matter what task). Basically I want working hours for each day for each each user.
I tried to do this:
enter work = MINX(
SUMMARIZE(events,events[Date Only].[Date],events[user_id],
"MINN",MIN(events[ConvertedTimeToInteger])
),
[minn]
)
exit work = MAXX(
SUMMARIZE(events,events[Date Only].[Date],events[user_id],
"MAXX",MAX(events[ConvertedTimeToInteger])
),
[MAXX]
)
It works for a daily calculation, but for a total calculation its not good as it takes min/max of the date period:
Any help much appreciated
Ok, I have found a solution!
I had to summarize by 2 columns :
duration = SUMX(SUMMARIZE(events,events[date].[Date],events[user_id],"datesesese",DATEDIFf([Enter time],[exit time],HOUR)),[datesesese])
Solution
Related
I work in production where we measure the time use of different machines. Basically I want to show my colleagues with a bar chart in PowerBI when most people start using the machine and when most people are done with the machine (showed in full hours, for example 7, 10, 16).
I have 2 column (start time & end time) that are in time format (16:30:00) that I've changed to whole numbers (Start time as number) and a end time as number that can't be seen in picture due to broad sheet. See below
Formula: Start time as number = HOUR(sheet1[Start time])
The problem I have occurred is when I take start time and end time in same table it shows exactly the same values? But if I make a table with start and a different with end, it shows the correct result. See below pictures:
Above is the merge of Start and End time but it should look like below
The left table above is start time and right table is end time of machine.
Thanks!
EDIT: When I try formula from Mik
EDIT Picture of my situation.
I think it's correct now! Will try on my main data.
Create a table for Ox scale with
Hours = GENERATESERIES(0,23,1)
This is a measure for start ( for end is the same just change the column name)
start =
COUNTROWS(
FILTER(
'sheet1'
,HOUR(sheet1[Start time])
=SELECTEDVALUE(Hours[Value])
)
)
end =
COUNTROWS(
FILTER(
'sheet1'
,HOUR(sheet1[End time])
=SELECTEDVALUE(Hours[Value])
)
)
I have a Power Bi dashboard tracking several metrics since the beginning of last month . Some of the comparisons I make are MTD vs Last MTD count of metrics like Total users, No of posts and connections made.
MTD(June) and LMTD(May) were working well last month(June) but when we moved to a new month(july) the numbers are off.
Here's my measure
MTD_Users = CALCULATE(COUNTROWS('reporting profiles'), FILTER('reporting profile', MONTH('reporting profile'[date_created])=MONTH(TODAY())))
LMTD_USERS = CALCULATE(COUNTROWS('reporting profiles'), FILTER('reporting profile', MONTH('reporting profile'[date_created])=MONTH(TODAY())-1))
Since July 2nd these measures are not displaying correct figures for MTD(July 1st) and LMTD(June 1st)
Any advice/assistance will be highly appreciated
You need to ride off contex filter and that mean we must use function ALL or REMOVEFILTERS;
https://dax.guide/removefilters/
https://dax.guide/all/
LMTD_USERS = CALCULATE(COUNTROWS('reporting profiles'), FILTER(ALL('reporting profile'[date_created])), MONTH('reporting profile'[date_created])=MONTH(TODAY())-1))
INTRO
I realize the title makes the problem sound simple, however, this task has proved incredibly difficult for me and it's taken up hours of my time every day for the past week. With that being said, any help is appreciated!
The first table involved is LoadView, which contains the fields LoadNumber, CarrierID, and BookedFrom. The second table is LoadBaseView, which contains the fields LoadNumber, CarrierID, and BookedOnDateTime. These two are related by LoadNumber.
The visualization I wanna add to is the following, where the new row would be "New Carriers" listed right under "Carriers":
Lastly, preliminary info wise, that table is just a matrix with LoadView[BookedFrom] as the only context (Autobook, etc.) and simple measures across LoadView along with it.
PROBLEM
Now that I've (hopefully) laid everything out clearly, let me explain exactly what I am looking for. I would like to count the amount of new carriers that have booked in each BookedFrom category, i.e. I would like to count the amount of carriers booking that have never booked before for each category. This means that any carrier could potentially be counted in each BookedFrom column, just to clarify. I've tried many different measure to capture this and I've run into a whole host of problems, including memory insufficiencies to exceeding available resources. The latter's DAX is the following:
IsFirstCarrierBookedFrom* =
Var current_booked_from = MIN(dsgLoadView[BookedFrom])
Var T1 = ADDCOLUMNS(ALL(dsgLoadView),"BookedOnDateTime",RELATED(dsgLoadBaseView[BookedOnDateTime]))
Var T2 = GROUPBY(T1,dsgLoadView[CarrierId],dsgLoadView[BookedOn],"MinBookedOnDateTime",MINX(CURRENTGROUP(),[BookedOnDateTime]))
Var T3 = NATURALINNERJOIN(T1,T2)
Var T4 = FILTER(T3,[BookedOnDateTime]=[MinBookedOnDateTime])
RETURN
CALCULATE(DISTINCTCOUNT([CarrierId]),FILTER(T4,[BookedFrom]=current_booked_from),USERELATIONSHIP(dsgLoadView[BookedOnDate],dsgCalendar[Date]))
The above results in this error:
This next attempt results in a memory insufficiency error:
TotalFirstCarrierBooks* =
Var current_row_carrier_id = MIN(dsgLoadBaseView[CarrierId])
Var current_row_booked_from = MIN(dsgLoadView[BookedFrom])
Var first_booked_from_date_time =
CALCULATE(
MIN(dsgLoadBaseView[BookedOnDateTime]),
FILTER(
ALL(dsgLoadBaseView),
dsgLoadBaseView[CarrierId]=current_row_carrier_id
),
FILTER(
All(dsgLoadView),
dsgLoadView[BookedFrom]=current_row_booked_from
)
)
Var is_first_date = IF(first_booked_from_date_time=MIN(dsgLoadBaseView[BookedOnDateTime]),1,0)
RETURN
SUMX(dsgLoadBaseView,is_first_date)
With that being said, if I take out the BookedFrom bits (current_row_booked_from, etc.) the measure works and when alongside LoadNumber it returns a 1 or 0, denoting that the LoadNumber was or was not the first booking by the Carrier. I decided this wasn't the right path, though, due to that memory error. Also, summing up these 1's gets me duplicate bookings per Carrier per BookedFrom. In other words, a Carrier can book 2 loads via Manual at the same DateTime and, as those 2 rows would have 1's per the logic, that would add up to 2 which is a no-no.
THANK YOU
Seriously, to anyone who got this far! This problem has eaten up a ton of time for me, I've Googled relentlessly and I've watched countless YouTube videos. Thanks for your time!
I unable to provide a solution that would work because I don't have the data and its impossible to solve questions like these without the actual data, but I do know DAX so based on my experience here are my suggestions.
For measure IsFirstCarrierBookedFrom:
Substitute DISTINCTCOUNT with SUMX ( VALUES ( Table[CarriedID] ), 1 ) and see if that resulst in better performance
You are adding a column to dsgLoadView with RELATED, what is the cardinality of this table? Pay attention to these details and based on that supply a smaller table to ADDCOLUMNS and then use CALCULATE to compute BookedOnDateTime
Functions like NATURALINNERJOIN utilize the slower engine of DAX
You are probably applying a huge table T4 into the filter context with CALCULATE
For measure TotalFirstCarrierBooks:
You are probably iterating a huge tabls inside CALCULATE in the variable first_booked_from_date_time, try to change that to this:
VAR first_booked_from_date_time =
CALCULATE (
MIN ( dsgLoadBaseView[BookedOnDateTime] ),
dsgLoadBaseView[CarrierId] = current_row_carrier_id,
dsgLoadView[BookedFrom] = current_row_booked_from,
REMOVEFILTERS ( dsgLoadBaseView ),
REMOVEFILTERS ( dsgLoadView )
)
The RETURN part isn't working how you would expect it to, variables in DAX are constants, before RETURN the value of is_first_date is computed and is now a fixed value, nothing can change it, let's assume it is 10 then inside SUMX ( dsgLoadBaseView, is_first_date ) you are summing 10 for each row of the table dsgLoadBaseView
I need to develop a report with a table that includes several dimensions and displays a sales revenue measure. Most of the times this measure throws a zero, but the user wants to visualize a blank space instead. I have searched around, but I couldnĀ“t find anything that gives me support. So if anyone has experimented this or found a workaround I would thank you for your time.
You could use a IF condition to replace 0 with blanks. For example, if you are summarizing a field called "Sales" the following formula would work:
Measure = IF(Sum(Sales)=0,"",Sum(Sales))
Hope this helps.
Adding the additional option based on Ricardo's suggestion:
Measure = IF(Sum(Sales)=0,Blank(),Sum(Sales))
If you have a measure [Measure] and you want to replace 0 with a blank, you can do the following:
MeasureReplaceBlank =
VAR Measure = [Measure]
RETURN IF ( Measure = 0, BLANK(), Measure )
Note that since I stored the calculation of [Measure] as a variable, I don't need to call it twice (once for the condition and once for the True branch of the IF function).
I need to calculate totals using a relationship which doesnt exist. I have the following anonymised tables:
Team
Eng
Job
Hours
My relationships are:
I want to calculate the total hours where Job.EngID = Hours.EngID AND Job.JobID = Hours.JobID, per team. What I want is:
I am part of the way there, but only if I want to show hours by engineer, not by team
HrsMeasure =
CALCULATE (
SUM ( Hours[Hrs] ),
FILTER ( Hours, Hours[EngID] = MAX ( Job[EngID] ) )
)
This gives me:
Is there anything I can do, without changing the data model/relationships?
See below the PBIX file:
https://1drv.ms/u/s!AuiIgc_S9J5JhbgBkRFKyNPYNoxxNA?e=gZBhi2
Cheers for all help
Edit 1 - So I have tried using an inactive relationship between Jobs and Hours but I still get the wrong values. This is done using a concatenated column of JobID/EngID on both Jobs and Hours tables:
HrsMeasureUSERELATIONSHIPJobEng =
CALCULATE (
SUM ( Hours[Hrs] ),
USERELATIONSHIP(Hours[JobEng],Job[JobEng])
)
Hope someone can help me on this as its driving me bonkers!
Cheers
So the answer was to create concatenated columns for JobID/EngID on both the Hours and Jobs tables. Join these two columns using an inactive relationship, and then use a CALCULATE with a USERELATIONSHIP to activate the inactive relationship - this has done the trick:
HrsMeasureUSERELATIONSHIPJobEng =
CALCULATE (
SUM ( Hours[Hrs] ),
USERELATIONSHIP(Hours[JobEng],Job[JobEng])
)