The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
Hi everyone,
Though I thought my problem was solved earlier this week: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Measure-to-filter-rows-based-on-two-dates-beg...
It unfortunately was not. (cannot seem to UNsolve that topic)
I am looking to get a measure with Active vehicles number, ClassStructure, By year (>= [PurchaseDate], <=[ReplacementDate], .
Presented but NOT correctly working option was:
-------------------------------------------------------------------------------------
#Vehicles Active =CALCULATE (
COUNTROWS ( FleetActivity ),
FILTER (ALL ( FleetActivity ),
FleetActivity[PurchaseDate] <= MAX ( dimDate2[Date_pk] )
&& FleetActivity[ReplacementDate] >= MIN ( dimDate2[Date_pk] )
))
-------------------------------------------------------------------------------------
>> My thinking is that the problem lies with the relationship to the Date table ( 1. with [PurchaseDate] and 2. with [ReplacementDate]), So I tried Userelationship: but it gives me the error that it can only be used in a Calculate syntax.
-----------------------------------------------------------------------------------
active vehicles userelationship = CALCULATE ( COUNTROWS ( FleetActivity ), FILTER ( ALL ( FleetActivity ), FleetActivity[PurchaseDate] <= MAX ( dimDate2[Date_pk] ) && Userelationship(FleetActivity[ReplacementDate],dimDate2[Date_pk]) >= MIN ( dimDate2[Date_pk] ) ))
------------------------------------------------------------------------------------
Date table and relationships:
I wanted to share a Pbix test file, but unfortunately it is not supported.
Also, Sorry I had to re-open this question: if anyone knows how to (UN)solve the other topic, happy to do that.
Thank you in advance!
Solved! Go to Solution.
SOLUTION:
1. remove connections to date table, then:
SOLUTION:
1. remove connections to date table, then:
Hi @REWINDER
I assume the active relationship is with the FleetActivity[PurchaseDate] coulmn, then please try
#Vehicles Active =
CALCULATE (
COUNTROWS ( FleetActivity ),
FleetActivity[PurchaseDate] <= MAX ( dimDate2[Date_pk] ),
FleetActivity[ReplacementDate] >= MIN ( dimDate2[Date_pk] ),
CROSSFILTER ( FleetActivity[PurchaseDate], dimDate2[Date_pk], NONE )
)
@tamerj1 ,
Thank you for the suggestion, but this solution too only counts total vehicles, and does not separate per Type.
Attempting to make a hybrid out of the three measures now.
Hi @REWINDER
Would you please provide sample data and on the same screenshot above manually type the correct expected results?
@REWINDER , change as per need
active vehicles userelationship = CALCULATE ( CALCULATE ( COUNTROWS ( FleetActivity )Userelationship(FleetActivity[ReplacementDate],dimDate2[Date_pk]) )
, FILTER ( ALL ( FleetActivity ), FleetActivity[ReplacementDate] <= MAX ( dimDate2[Date_pk] ) && FleetActivity[ReplacementDate] >= MIN ( dimDate2[Date_pk] ) ))
You need the filter you have used only when you want filter purchase date not the replacement date
this should do
CALCULATE ( COUNTROWS ( FleetActivity )Userelationship(FleetActivity[ReplacementDate],dimDate2[Date_pk]) )
example
@amitchandak , Thank you.
Though it gets the right values at the end of the date range,
at the beginning, it only starts counting values from the Replacement date, see figure 1. Figure 2 at end of Date range. (measures above table for reference).
So the measure on the right gets the numbers right, but is unable to split it by ClassStructure.
User | Count |
---|---|
28 | |
12 | |
8 | |
7 | |
5 |
User | Count |
---|---|
35 | |
14 | |
12 | |
9 | |
7 |