Forum Discussion

snoozee's avatar
snoozee
Regular Visitor
2 years ago
Solved

Weekly Check Calculation

Hi

 

I have a table that contains the following columns

 

Location, Date, CheckNotCompleted. WeekNumber and Year

 

My CheckNotCompleted column contains a Yes or No response

 

I need DAX to create a new column that will look at the CheckNotCompleted column for each week number and Location and if the week for that location has a Yes response in it then return Yes for all of the relavent week days for that week, if the column doesn't have a Yes response for that week then the reponse would be No..

 

Is this possible ??

  • Hi snoozee ,

     

    Based on the screenshot you provided, you need to change the code slightly as follows.

    Weekly Check = 
    VAR CurrentLocation = 'Table'[Location]
    VAR Cnt =
        CALCULATE (
            COUNT ( 'Table'[CheckNotCompleted] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[WeekNumber] ),
                'Table'[CheckNotCompleted] = "Yes"
                    && 'Table'[Location] = CurrentLocation
            )
        )
    RETURN
        IF ( Cnt >= 1, "Y", "N" )

    Result is as below.

    Hope that works for you.
    For further details,please find attachment.


    Best Regards,
    Yulia Yan


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

6 Replies

  • Hi,

    I am not sure how your semantic model looks like, but I tried to create a sample pbix file like below.

    Please check the below picture and the attached pbix file.

     

     

    WINDOW function (DAX) - DAX | Microsoft Learn

     

    Expected result CC =
    VAR _t =
        FILTER (
            WINDOW (
                1,
                ABS,
                -1,
                ABS,
                Data,
                ORDERBY ( Data[Date], ASC ),
                ,
                PARTITIONBY ( Data[Location], Data[Year], Data[Week Number] ),
                MATCHBY ( Data[Location], Data[Date] )
            ),
            Data[CheckNotCompleted] = "Y"
        )
    RETURN
        IF ( COUNTROWS ( _t ) >= 1, "Y", "N" )
    

     

    • snoozee's avatar
      snoozee
      Regular Visitor

      Jihwan_Kim  Thank you so much for replying so quickly !!

       

      Unfortunately this doesn't work for me as i'm getting an error of - Cannot find name 'Window' , 'Window' is not a function, Parameter is not the correct type.

       

      This is probably related to the version of Power Bi I'm using  - May 2021 and unfortunately i can't update it as it's controlled by my work 😞

       

      This is also the reason why i can't open your attachment either.

       

      Is there any other option available ?

  • v-weiyan1-msft's avatar
    v-weiyan1-msft
    Community Support

    Hi snoozee ,

     

    Jihwan_Kim nice method! Thank you, for your helpful and quick response.

    And you can also consider using the following code to create a Calculated column.

    Weekly Check = 
    VAR CurrentLocation = 'Table'[Location]
    VAR Cnt =
        CALCULATE (
            COUNT ( 'Table'[CheckNotCompleted] ),
            FILTER (
                ALLEXCEPT ( 'Table', 'Table'[WeekNumber] ),
                'Table'[CheckNotCompleted] = "Y"
                    && 'Table'[Location] = CurrentLocation
            )
        )
    RETURN
        IF ( Cnt >= 1, "Y", "N" )

    My Sample:

    Result is as below.

     

    Best Regards,
    Yulia Yan


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

    • snoozee's avatar
      snoozee
      Regular Visitor

      Hi v-weiyan1-msft 

      Thanks for getting back to me yet unfortunately it's not working as all of the results are 'N'  😣

      The example below should be displaying 'Y' for all of these dates as a check was completed within the week.

       

      Weekly Check =
      VAR CurrentLocation = 'CameraDate'[Branch]
      VAR Cnt =
      CALCULATE (
      COUNT ( 'CameraDate'[CheckNotCompleted] ),
      FILTER (
      ALLEXCEPT ( 'CameraDate', 'CameraDate'[WeekNumber] ),
      'CameraDate'[CheckNotCompleted] = "Y"
      && 'CameraDate'[Branch] = CurrentLocation
      )
      )
      RETURN
      IF ( Cnt >= 1, "Y", "N" )

       

       

       
      • v-weiyan1-msft's avatar
        v-weiyan1-msft
        Community Support

        Hi snoozee ,

         

        Based on the screenshot you provided, you need to change the code slightly as follows.

        Weekly Check = 
        VAR CurrentLocation = 'Table'[Location]
        VAR Cnt =
            CALCULATE (
                COUNT ( 'Table'[CheckNotCompleted] ),
                FILTER (
                    ALLEXCEPT ( 'Table', 'Table'[WeekNumber] ),
                    'Table'[CheckNotCompleted] = "Yes"
                        && 'Table'[Location] = CurrentLocation
                )
            )
        RETURN
            IF ( Cnt >= 1, "Y", "N" )

        Result is as below.

        Hope that works for you.
        For further details,please find attachment.


        Best Regards,
        Yulia Yan


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