I am using the summarize function to group items by job, and find the latest ship date for any items on that job using the MAX function. For whatever reason on some of the lines (about 3%), the max function doesn't seem to work. Doing some digging it looks like the MIN function seems to give me the result I'm looking for, anyone have ideas on why this is? Below is the code I'm using, as well as a picture of one job that I'm having issues with.
Data summarized =
SUMMARIZE(
Data, Data[SLT - SO#],
"Max Ship Date", Max(Data[SO Seq Actual Del Date]),
"Min Ship Date", MIN(Data[SO Seq Actual Del Date])
)
Try this:
Data summarized =
ADDCOLUMNS (
SUMMARIZE ( Data, Data[SLT - SO#] ),
"Max Ship Date", CALCULATE ( MAX ( Data[SO Seq Actual Del Date] ) ),
"Min Ship Date", CALCULATE ( MIN ( Data[SO Seq Actual Del Date] ) )
)
Related
We're a trucking company. I have a measure that gives me a total number of drivers within a date range context. I really need an average. My thought was to use AVERAGEX to create the average utilizing the count measure I created.
I have not had much luck. There is enough internet resources to say it should be possible, but I can't seem to put the components together.
This is my Driver Count measure.
Driver Count (Company) =
CALCULATE (
COUNTROWS ( Drivers ),
FILTER (
VALUES ( 'Drivers'[Hire Date] ),
'Drivers'[Hire Date] <= MAX ( Dates[Date] )
),
FILTER (
VALUES ( 'Drivers'[Termination Date] ),
OR(
Drivers[Termination Date] >= MIN ( Dates[Date] ),
ISBLANK ('Drivers'[Termination Date] )
)
),
FILTER(
Drivers,
Drivers[Activated] = "Y"
),
FILTER(
Drivers,
Drivers[Type] = "Company"
)
)
And this is the driver table I'm working with...
Any resources you can point me to in order to learn what I need to know would be greatly appreciated. I would also welcome alternative methods (like making transforming that driver count measure into a driver average measure).
I tried this adapted from a similar problem solved here on Stack Overflow, but I have to be honest and did not expect it to work.
Avg Driver Count (Company) =
AVERAGEX(VALUES(Drivers[Code]),
[Driver Count (Company)])
It resulted in '1.00' for every date range. That makes sense to me, actually. So, I suspect I have the wrong value in 'VALUES'.
I'm conducting an exercise around examining test results after tutoring has occurred. Essentially looking at the rates of "pass" post tutoring within the context of a given student. Where the ultimate outcome would be:
pass rate after tutoring = [count passes]/[count test date] WHERE test date > tutoring date.
For example:
Ideally, the final output of the measure would be = 1 (1/1)
Would anyone be able to point me in the direction of achieving this through a Power BI measure?
I've attempted the following to get the single oc with no luck:
Measure 3 = CALCULATE(COUNT(Table[Test Pass?]),FILTER(Table,Table[Test Date]>CALCULATE(Min(Table[Tutoring Date]),FILTER(Table,Table[Tutor (?)] <> BLANK ))))
Where I would then use the student column in a matrix with the measure to group pass rates post tutoring by student
I have used this simple flat table data model:
You can calculate this with a measure that needs to be evaluated with your Student column:
Pass Rate After Tutoring =
VAR _tutor_date =
CALCULATE (
MAX ( 'Table'[Tutoring Date] ),
ALLEXCEPT ( 'Table', 'Table'[Student] )
)
VAR _tests_post_tutor =
CALCULATE (
COUNTROWS ( 'Table' ),
ALLEXCEPT ( 'Table', 'Table'[Student] ),
'Table'[Test Date] > _tutor_date
)
VAR _successes =
CALCULATE (
COUNTROWS ( 'Table' ),
ALLEXCEPT ( 'Table', 'Table'[Student] ),
'Table'[Test Date] > _tutor_date,
'Table'[Test Pass]
)
RETURN
DIVIDE ( _successes, _tests_post_tutor )
But this assumes that students are only tutored for one specific test, and are tutored once.
I need to write a DAX measure that calculates (e.g., "Count Rows"), but only when another measure value is evaluated (e.g., filtering "[Sales]>100"). So if-- in the context of the selected filters-- Sales is great than 100, then the measure is executed only for those rows.
The measure I have defined works in the context of lower smaller grain. But the totals do not sum correctly.
Any suggestions?
DAX Measure
License Usage =
// Users with active viewership in 3 months
IF (
NOT ( ISBLANK (
CALCULATE (
[Activity Date NEWEST],
KEEPFILTERS ( DATESINPERIOD ( dimCalendar[Date], TODAY (), -90, DAY ) )
)
)), 1
)
Activity Date NEWEST =
MAX('PBI Activity'[Date])
Okay, I figured something out that works.
DAX
License Usage =
// Users with active viewership in 3 months
CALCULATE (
[Count Users],
FILTER ( 'PBI Activity', 'PBI Activity'[Date] >= TODAY () - 90 )
)
Count Users = COUNTROWS('Users')
Also, I later came across this article which looks like it also does what I was hoping to do: Execute calculate expression over filtered rows based upon measure filter.
Reference: Specifying multiple filter conditions in CALCULATE - SQLBI
DAX
DEFINE
MEASURE Sales[Big Sales Amount] =
CALCULATE (
[Sales Amount],
KEEPFILTERS (
FILTER (
ALL ( Sales[Quantity], Sales[Net Price] ),
Sales[Quantity] * Sales[Net Price] > 1000
)
)
)
EVALUATE
SUMMARIZECOLUMNS (
Sales[Quantity],
"Sales Amount", [Sales Amount],
"Big Sales Amount", [Big Sales Amount]
)
Hi I have been struggling with this for a bit now and I hope I didn't miss a previous question. I am trying to get a count of the vehicles we have based on an EOMONTH date. We are buying and selling cars on a regular basis and for reporting we need to know how many we had at the end of each month and the report is a rolling 12 months.
I've tried creating the relationship with the purchasedate of the vehicle to the date of my date table but when I create the measure (Used to calculate the number of vehicles purchased but haven't been sold):
SalesBlank = CALCULATE(
COUNT(Vehicles[MVANumber]),
FILTER(Vehicles, Vehicles[purchasedate] <= RELATED('Date'[EOMONTH]) && ISBLANK(Vehicles[saledate])))
I only get a count of vehicles purchased that month and don't have a sale date - I'm not surprised because my relationship with the date table is the purchase date.
How can I set up a measure to look at the date table and filter the vehicles table with this logic:
purchasedate <= date[EOMONTH] && ISBLANK(salesdate)
Any help would be greatly appreciated!!
Thanks,
Matt
Sample Data and Desired Results
Relationships
If I understand you correctly, you want to get a count of the vehicles on hand at the end of each month. That could be calculated by counting the vehicles with a purchase date less than or equal to the selected end of month and subtracting the count of vehicles with a sale date less than or equal to the selected end of month.
You can create an active relationship between Vehicle[PurchaseDate] and Date[Date]. Then create an inactive relationship based upon Vehicles[SaleDate] and Date[Date].
You could use a measure that is something like this:
Inventory Count =
VAR MaxDate =
MAX ( 'Date'[Date] )
VAR MinDate =
CALCULATE ( MIN ( 'Date'[Date] ), ALL ( 'Date' ) )
VAR Purch =
CALCULATE (
COUNT ( 'Vehicles'[VehicleID] ),
DATESBETWEEN ( 'Date'[Date], MinDate, MaxDate )
)
VAR Sales =
CALCULATE (
COUNT ( 'Vehicles'[VehicleID] ),
USERELATIONSHIP ( 'Date'[Date], Vehicles[Sale Date] ),
DATESBETWEEN ( 'Date'[Date], MinDate, MaxDate )
)
VAR MaxPurDt =
CALCULATE ( MAX ( 'Vehicles'[Purchase Date] ), ALL ( 'Vehicles' ) )
VAR MaxSlDt =
CALCULATE ( MAX ( 'Vehicles'[Sale Date] ), ALL ( 'Vehicles' ) )
RETURN
IF (
MIN ( 'Date'[Date] ) <= MaxPurDt
|| MIN ( 'Date'[Date] ) <= MaxSlDt,
Purch - Sales
)
This measure gets a cumulative count of purchases and a cumulative count of sales and then subtracts them. The IF check is to avoid propagation of cumulative totals beyond the maximum date in the Vehicle table.
I'm not sure how to interpret your showing of just 3 months in the desired results. This will produce the same answers as what you have, but without a filter applied to the table, it starts at 3/31/2016 (the date of the first sale).
Edit: There's probably a more efficient way along the lines you were thinking, but it is escaping me at the moment.
I want to dynamically change the number format of a DAX measure, based on a dimension value (or indeed, based on the order of magnitude of the measure value).
I understand I can use SWITCH and FORMAT, as demonstrated by Kaspar De Jonge here: https://www.kasperonbi.com/dynamic-format-using-dax/
Here's an example of the type of measure I'm creating:
My Measure:=IF (
HASONEVALUE ( dimMeasureType[Measure Type] ),
SWITCH ( VALUES ( dimMeasureType[Measure Type] ),
"Total Cost", FORMAT ( [Total Cost], "#,##0, k" ),
"Cost Per Unit", FORMAT ( [Cost Per Unit], "#,##0.00" ),
"Cost % Sales", FORMAT ( [Cost % Sales], "0.00%" ),
BLANK()
),
BLANK()
)
But this technique returns text measures. I need to be able to chart my measures, so I do not want to convert them to text. Is there another technique for dynamically changing a measure number format, without converting to a string?
If it makes a difference, I'm working in SSAS-Tabular on SQL Server 2016 BI.
I don't believe this is currently possible, but it a popular feature request that will hopefully be implemented in the future.
I recommend voting and commenting on the idea I linked to in order to add your support.
A workaround is to create multiple measures and add them all to your chart. Depending on your dimension value only one measure returns values, all other measures return BLANK() and are not displayed in your chart. You can give them the same display name by adding whitespace to the end of their names:
My Measure:=IF (
SELECTEDVALUE( dimMeasureType[Measure Type] ) = "Total Cost",
[Total Cost],
BLANK()
)
[My Measure ]:=IF (
SELECTEDVALUE( dimMeasureType[Measure Type] ) = "Cost Per Unit",
[Cost Per Unit],
BLANK()
)
[My Measure ]:=IF (
SELECTEDVALUE( dimMeasureType[Measure Type] ) = "Cost % Sales",
[Cost % Sales],
BLANK()
)
This has some drawbacks though:
The chart legend shows all measures, even if all their values are BLANK().
The y-Axis of your chart has the same format as the first measure in its 'Values' section.