Forum Discussion
DAX FUNCTION
- 9 years ago
Assuming that Table1 is your table name, the first column is of date type (and is called Date) and there is a measure called Sales = sum(Table1[KPIValue]), then use the formula below
Test =
VAR LastDateWithSales =
CALCULATE (
MAX ( Table1[Date] ),
FILTER ( ALL ( Table1 ), Table1[Date] <= MAX ( Table1[Date] ) && [Sales] > 0 )
)
RETURN
CALCULATE ( [Sales], Table1[Date] = LastDateWithSales )i got the below result
- 9 years ago
Is the Region coming from a master (lookup) table or is it part of the same Table? If part of the same table, you can just use an ALLEXCEPT
VAR LastDateWithSales =
CALCULATE (
MAX ( Table1[Date] ),
FILTER ( ALLEXCEPT ( Table1, Table1[Region] ), Table1[Date] <= MAX ( Table1[Date] ) && [Sales] > 0 )This will ensure that the LastDAte is calculated after the filter on Region is done. If Region is coming from a lookup table, you can use the ALLEXCEPT for the field in Table1 that is connecting to the Region lookup table.
True, I missed that part. In the case SqlJason formula will work, Do you see any challenge with that?
That is where it is helpful to understand your tables, if you have continuous calendar table, it will help to make time based calculation easy. In case you don't have calendar table, here is the link on how you can create one and link your data table to calendar table.
- Sean9 years agoCommunity Champion
Take your pick :smileyhappy:
Month Order = INT ( CONCATENATE ( YEAR ( 'Calendar'[Date] ), CONCATENATE ( IF ( MONTH ( 'Calendar'[Date] ) < 10, "0", "" ), MONTH ( 'Calendar'[Date] ) ) ) )or the easier version
Month Order 2 = INT ( CONCATENATE ( YEAR ( 'Calendar'[Date] ), FORMAT ( 'Calendar'[Date], "MM" ) ) )or the easiest version :smileyhappy:
Month Order 3 =
VALUE ( FORMAT ( Calendar[Date], "YYYYMM" ) )All 3 do the same! :smileyhappy:
- SqlJason9 years agoMemorable MemberOr even easier,
month order = VALUE(FORMAT(Calendar[Date], "YYYYMM"))