Forum Discussion

Anil59060's avatar
Anil59060
Frequent Visitor
5 years ago
Solved

Return a value if selected date is between two dates

Hello, I am creating a power bi dashboard for machines shutdown planning. Let's say I have 5 machines. Each machine undergoes one or two maintenances every year. During each maintenance period, capa...
  • Anonymous's avatar
    Anonymous
    5 years ago

    Hello @Anil59060

    You may want to display values in this calculation logic:

    If DATE is not on the SD date, display the values in the capitalization table (specific machine).

    If Date in SD DATE, it displays 0.

    I think you can test the IF function to achieve your goal.

    I build a table like yours to test me.

    Capitalization table:

    1.png

    Tabla SD:

    2.png

    Create a date table:

    Date = ADDCOLUMNS(CALENDARAUTO(),"Month",FORMAT([Date],"MMM"))

    Measure:

    Machine 1 = 
    VAR _SD_Start =
        CALCULATE ( MAX ( SD[SD Start] ), FILTER ( SD, SD[Machine] = "Machine 1" ) )
    VAR _SD_End =
        CALCULATE ( MAX ( SD[ SD End] ), FILTER ( SD, SD[Machine] = "Machine 1" ) )
    VAR _Value =
        CALCULATE ( SUM ( Cap[Machine 1] ), FILTER ( Cap, Cap[Month] = 'Date'[Month] ) )
    RETURN
        IF ( 'Date'[Date] >= _SD_Start && 'Date'[Date] <= _SD_End, 0, _Value )

    Result:

    3.png

    Other measurements of the machine are the same, you just need to change the three measurements in var.

    You can download the pbix file from this link: Return a value if the selected date is between two dates

    Best regards

    Rico Zhou

    If this post helps,then consider Accepting it as the solution to help other members find it faster.