I've this Measure in Power BI to calculate the average value ignoring low values (lower than the complete average previously calculated)
Measure =
var T1 =
SUMMARIZE(RAD,RAD[deviceid],"SUMDEVICE",SUM(RAD[data]))
VAR AVGDEVICE =
AVERAGEX(T1,[SUMDEVICE])
RETURN
AVERAGEX(T1, IF([SUMDEVICE]>=AVGDEVICE,[SUMDEVICE]))/1000
In this page I have two slices, one to select a time range and other to select a device. In this case, for this measure I want to ignore the device filter from the slicer, only with the date filter.
The RAD table is simple, and it is something like this, I have 4 devices and data for all the days of the year:
Date
DeviceId
Data
01/01/2022
A
100
01/01/2022
B
120
01/01/2022
C
90
01/01/2022
D
74
I can't find how to ignore this filter and have a fixed value for the selected time range in the slicer.
Thanks!
Try this one.
Measure =
var T1 =
CALCULATETABLE(
SUMMARIZE(RAD,RAD[deviceid],"SUMDEVICE",SUM(RAD[data]))
,ALL(RAD[deviceid]) -- works if the slicer is of this column or change to the proper tableName[columName]
)
VAR AVGDEVICE =
AVERAGEX(T1,[SUMDEVICE])
RETURN
AVERAGEX(
FILTER(
T1
,[SUMDEVICE]>=AVGDEVICE
)
,[SUMDEVICE]
)/1000
Related
I have a table like shown below:
ID
Date
Asset
Location
145
7/29/22
A
Market
145
7/30/22
A
Warehouse
145
7/29/22
B
Market
145
7/29/22
C
Truck
150
7/30/22
B
Market
145
7/29/22
D
Market
145
7/30/22
A
Market
What I am trying to accomplish is to get a distinct count of IDs for each date with a location filter as well. So I would want a count of ID based on the slicer selected Date of 7/29/22 AND 7/30/22 for the Market Location. The desired result is 2 for the selected dates from the date slicer which directly corresponds to the date column in the table.
I was trying to use this DAX formula and wasn't getting anywhere....
IDsMarket =
CALCULATE (
DISTINCTCOUNT ( 'Products'[ID] ),
ALL ( 'Products' )
)
I have a measure dropped onto a card. I should have specified that. My apologies. I need 1 measure to show me the combined count for the two days selected.
I tried this with countrows as well but of course the result wasn't distinct... Any help would be greatly appreciated!!
The formula you're looking for is
IDsMarket =
CALCULATE(
DISTINCTCOUNT('Products'[ID]),
'Products'[Location] = "Market"
)
The resulting Table will look like this
But if you put the measure on a Card visual, you'll get
So in DAX the same measure can yield 1000 different values - depending on the filter context.
I created a conditional column in Power Query and combined the ID with the "day" number from the date column which allowed me to then do a distinct count on that combined custom column which produced to correct answer. Sorry for all the confusion. One of those days.
I need a DAX measure that gives me the sum of durations for multiple categories restricted by a date slicer.
In this simplified example there are 2 categories with 3 subcategories each. A DateTime Slicer on the dashboard is set to the timespan of 2nd of January 2021 noon to 6th of January midnight. I need the summed up duration of all categories in this timespan.
Input data:
A table containing multiple rows for each category with a start date and an end date.
The complicated part is that there are pauses between the timestamps.
Desired output:
A table on the dashboard containing the category and a calculated measure for the summed up duration during the sliced timespan.
When changing the slicer the meaure shall change as well.
My current solution for this problem is an M formulato create a list of all days in each timespan and to unpivot all lists. In the dashboard the count of rows gives you the number of days in the selected timespan. This solution though reqires a much larger input table and soes not work if you want to be exact on the second, only on days.
I tried so solve this via a measure but didn't make any progress worth showing here.
all datetime values are in the format dd.mm.yyyy hh:mm:ss (24h system)
I found a way to do it by using 2 measures.
First measure calculates the time during the timespan for each element:
I use one Date Table only consisting of all dates available which is the input for the slicer and the data Table called "Data".
duration_in_timespan_single =
VAR MinTs = MIN ('Date'[Date])
VAR MaxTs = MAX ('Date'[Date])
VAR MinUtcMin = MIN ('Data'[Date_Start])
VAR MaxUtcMax = MAX ('Data'[Date_End])
RETURN
IF(
AND(MinUtcMin >= MinTs, MinUtcMin <= MaxTs),
IF(
MaxUtcMax <= MaxTs,
CONVERT((MaxUtcMax-MinUtcMin),DOUBLE),
CONVERT((MaxTs-MinUtcMin),DOUBLE)),
IF(
MinUtcMin < MinTs,
IF(
MaxUtcMax > MinTs,
IF(
MaxUtcMax <= MaxTs,
CONVERT((MaxUtcMax-MinTs),DOUBLE),
CONVERT((MaxTs-MinTs),DOUBLE)
),
0
),
0
)
)
The second measure just sums up the first for each category:
duration_in_timespan = SUMX('Data',[duration_in_timespan_single])
I had an issue with Power bi date slicer.
I need solve when select date slicer
date value in axis visualization will be same value in slicer and +7 day
example i select date is 5/05/2021
output is date value in axis is 5/12/2021
If the table in your slicer is related to your fact table you won't need SELECTEDVALUE.
Assuming it is marked as date table.
My Measure +5 days = CALCULATE([My measure], DATEADD(Date[Date],1,day)
If not and you have autodatetime on.
My Measure +5 days = CALCULATE([My measure], DATEADD(Date[Date].[Date],1,day)
With SELECTEDVALUE if it is a parameter table.
My Measure +5 days =
VAR _selecteddate = SELECTEDVALUE(Date[Date])+5
RETURN
CALCULATE([My measure],'myTable'[Date] = _selecteddate)
I am looking for unit counts when the equipment is not in the date range (start and end dates).
How do I make a measure "AvailUnitCount" to give me unit counts by category in the timeline dimension (say November 11, 2018)?
I think it can be achieved via a measure in Power Pivot and date table, but I am just quite new to DAX and time dimension concept overall.
My measure reads:
AvailUnitCount := CALCULATE( DISTINCTCOUNT( EquipUsage[EquipmentNo] ) )
How do I incorporate time dimension into the measure above, so I can report on available equipment for a specific date by moving a timeline in Excel?
Please see the data set and the desired outcome below. I immensely appreciate your advice on this.
Table 1: EquipUsage
EquipNo CategoryNo UsageStartDate UsageEndDate
----------------------------------------------------
10005164 A020004004 5-Nov-18 5-Dec-18
10005167 A020004004 24-Oct-18 10-Nov-18
10005176 A020004005 9-Oct-18 5-Dec-18
10015982 A020004006 18-Feb-18 5-Sep-18
10019170 A020004006 16-Aug-18 30-Mar-19
10019551 A020004006 2-May-17 10-Nov-18
10005178 A020004007 20-Sep-18 15-Jan-19
Table 2: EquipCategories (Example of Desired Outcome for November 11, 2018)
CategoryNo AllUnits AvailableUnits
--------------------------------------
A020004004 2 1
A020004005 1 0
A020004006 3 2
A020004007 1 0
The AllUnits measure is simple:
AllUnits = COUNTROWS(EquipUsage)
For availability, read in your desired date and sum up the rows where that date does not fall in the given date range:
AvailableUnits =
VAR CheckDate = SELECTEDVALUE(DateTable[Date])
RETURN SUMX(EquipUsage,
IF(
EquipUsage[UsageStartDate] <= CheckDate &&
EquipUsage[UsageEndDate] >= CheckDate,
0,
1
)
)
I have a table of defect data that I would like to create a MEASURE that gives me a count of defects for each month. I know I need to use a date table but my attempts thus far haven't worked out.
What I am looking for when this works is a simple count by month:
January 125
February 225
March 220
April 120
Defect Table
Date Table
Here is the Measure I was trying to build without any luck...
Monthly Defects =
// TOTALYTD(COUNT(Defects[Defect]), 'Date'[Date])
VAR defectDate = FIRSTDATE(Defects[Created Date])
VAR defectYear = YEAR(defectDate)
VAR defectMonth = MONTH(defectDate)
RETURN
CALCULATE (
COUNT(Defects[Defect]),
FILTER (
Defects,
Defects[Created Date] <= defectDate &&
(YEAR (Defects[Created Date]) = defectYear) && (MONTH(Defects[Created Date]) = defectMonth)
)
)
Here is what I am looking to do in the end.
If you simply want a count per month, then your measure should be
Monthly Defects=COUNTROWS(Defects)
This is assuming that you have a relationship between your defect table and your date table.