Forum Discussion

cyborgandy's avatar
cyborgandy
Helper II
2 years ago
Solved

Last Half Yearly Data

Hi All I have below table in my power bi dashboard, I want to write a dax to show the total out of term count of pervious year half yearly data on the basis of selected calendar period in the page, f...
  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi cyborgandy 

     

    Please try this:

    First of all, I create a set of sample:

    Then add a new measure:

    MEASURE =
    VAR _selectDate =
        MAX ( 'Table'[Date] )
    VAR _currentCompany =
        MAX ( 'Table'[Company] )
    VAR _Half =
        FILTER (
            ALL ( 'Table' ),
            MONTH ( 'Table'[Date] ) >= 1
                && MONTH ( 'Table'[Date] ) <= 6
                && YEAR ( 'Table'[Date] )
                    = YEAR ( _selectDate ) - 1
                && 'Table'[Company] = _currentCompany
        )
    VAR _Later =
        FILTER (
            ALL ( 'Table' ),
            MONTH ( 'Table'[Date] ) >= 7
                && MONTH ( 'Table'[Date] ) <= 12
                && YEAR ( 'Table'[Date] )
                    = YEAR ( _selectDate ) - 1
                && 'Table'[Company] = _currentCompany
        )
    RETURN
        IF (
            MONTH ( MAX ( 'Table'[Date] ) ) >= 1
                && MONTH ( MAX ( 'Table'[Date] ) ) <= 6,
            CALCULATE ( SUM ( 'Table'[Value] ), _Half ),
            CALCULATE ( SUM ( 'Table'[Value] ), _Later )
        )

    The result is as follow:

     

    Best Regards

    Zhengdong Xu
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.