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])
)
)
Related
I think I have just been staring at this for too long and have worked myself into a corner.
So let's say I have the following data:
I have locations that get monthly utility usage numbers. I want to create a clustered bar chart that shows how many months have data.
The "Merge_Use" column can have numbers, blanks, and N/A. Any number > 0 OR N/A is considered complete. 0 or blank is incomplete.
I want a clustered bar chart that shows % complete, and is split by quarter and metric type, that shows the global total % complete, but can be filtered to show the % complete by region or individual location (relationships for TRT_ID to region is housed in a separate table). For some reason I can't wrap my mind around the measure that would do that.
This was my first try. I used a calculated column, but it wasn't until after I got to the visual stage that I realized that my calculated column is static and won't be affected by filtering. (It sounds silly now but I made a column that assigned each completed field a % out of the total fields, i.e. 1/total # rows, thinking I could just sum these together in the visual).
How would you do this?
I may have solved my own problem.
I added a conditional column with Yes/No for "completed" based off my criteria. (i.e. if "" then "No", else "Yes")
Then added the following measure:
% YES =
DIVIDE (
CALCULATE ( COUNT ( Leadership_Usage_Tracking_v2[Completed] ), Leadership_Usage_Tracking_v2[Completed] = "YES" ),
CALCULATE ( COUNT ( Leadership_Usage_Tracking_v2[Completed] ), ALLSELECTED ( Leadership_Usage_Tracking_v2[Completed] ) )
)
Seems to be working so far!
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 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
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 am new to power BI and stuck with an issue. I have my model as follows:
Date Dimension
Measurement Fact
The date column in Date Dimension is link to measuredate in Measurement Fact
Below is a sample data:
NB: In edit query, I have changed the type of measuredate to Date only.
I have tried the measure below but it doesn't work the way I want. It will sum all the values of the day but what I want is the last value of the day:
day_fuel_consumption =
CALCULATE (
SUM ( measurement[measurementvalue] ),
FILTER (
measurement,
measurement[metername] = "C-FUEL"
&& measurement[measuredate] = MAX ( measurement[measuredate] )
)
)
My Goal is to get 29242, i.e the last value of the day. Remember that measuredate is a Date field and not Datetime (I changed to Date field so that my Year and Month filter can work correctly). I have changed the type in edit query.
Changing your measure to use a variable could be the solution:
DFC =
var maxDate = MAX(measurement[measuredate])
return
CALCULATE(
SUM(measurement[measurementvalue]),
measurement[measuredate] = maxDate
)
However, you should keep the datetime format for measureDate. If you don't want to see the time stamp just change the format I power bi. Otherwise power bi will see two values with max date and sum them, instead of taking the last one.
Well, if you want to avoid creating a measure, you could drag the fields you are filtering over to the visual filters pane. Click your visual, and scroll a tiny bit and you will see the section I am referring to. From there, just drag the field you are trying to filter In this case, your value. Then select "Top N". It will allow you to select a top (number) or bottom (number) based on another field. Strange enough, it does allow you to do top value by top value. It doesn't make sense when you say it out loud, but it works all the same.
This will show you the top values for whatever value field you are trying to use. As an added bonus, you can show how little or how many you want, on the fly.
As far as DAX goes, I'm afraid I am a little DAX illiterate compared to some other folks that may be able to help you.
I had to create two separate measures as shown below for this to work as I wanted:
max_measurement_id_cf = CALCULATE(MAX(measurement[measurementid]), FILTER(measurement, measurement[metername] = "C-FUEL"))
DFC =
var max_id_cf = [max_measurement_id_cf]
return
CALCULATE(SUM(measurement[measurementvalue]), measurement[measurementid] = max_id_cf)