Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Time intelligence issues

Hi I'm new to Power BI but very familiar with both Tableau and Qlik Sense.   I want to make a distinct count of a logid both last month and three months back, thus I can calculate the change over ...
  • AntrikshSharma's avatar
    6 years ago

    Anonymous  Use ALL for removing active filters from the Calendar table.

     

    Test2 =
    VAR LastMonth =
        MAX ( 'Calendar'[monthKey] ) - 1
    RETURN
        CALCULATE (
            DISTINCTCOUNT ( TableA[logid] ),
            FILTER (
                ALL ( 'Calendar' ),
                'Calendar'[monthKey] = LastMonth
            )
        )

     

  • AntrikshSharma's avatar
    AntrikshSharma
    6 years ago

    Let's say you are currently looking at March, for march what all dates are available in the current filter context? all the days of the march, if you want to go back and forward in time you need to have all the dates in the current filter context, now how do you get whole of the dates table in each cell of a visual? you use ALL it return whole date table ignoring any filter coming from any where in the report, now you can use this to move back or forward in dates. so When you are at March, you will have whole Calendar containg all the years that you have defined in the calendar table, here is an example of running total.

     

    When I am at 1/1/2007, what is the max date? it is 1/1/2007, when I am at 1/10/2007 then what is the max date? it is 1/10/2007, when I am at Month level of January, what is the max date? it is 1/31/2007, now when we use ALL we can use this MAX function to get all the dates before the MAX date from our report.

     

    but in case if we weren't using ALL, at the day level we would always get one row from the calendar table, but in order to get all the dates less that 10th I need to have a table that returns all the dates so that I can define my MIN and MAX or any other date operation.

     

    With each increment in dates, FILTER gets the list of all the dates that are less than the date of the current cell in the visual and with this it is able to do a running total from the begining.

     

     

    Running Total = 
    VAR MaxDateInFilterContext = MAX ( Dates[Date] ) -- The max date from the current cell in the visual
    VAR MaxYear = YEAR ( MaxDateInFilterContext ) -- Year of the max date to reset the running total next year
    VAR DatesLessThanMaxDate =
        FILTER (
            ALL ( Dates[Date], Dates[Calendar Year Number] ),
            Dates[Date] <= MaxDateInFilterContext -- Get all the dates that are less than the max dates
                && Dates[Calendar Year Number] = MaxYear -- For the current year
        ) -- List of dates that are less than 1/11 just an example
    VAR Result =
        CALCULATE ( [Total Sales], DatesLessThanMaxDate ) --push all the list of dates into the filter context and                                                               evaluate the measure
    RETURN
        Result