Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dax measure

Hi,

So I have a dataset with a date column however I want to use a dax measure to on calculate anything within the last week of every month.

The values that will be calculated are the number of agreements in the last week of every month.

This will then be made into a percentage.
Can anyone help me with this please 

 

  • Hi, Anonymous 

     

    Since the sample you share is not representative and you didn't give the desired results, I can only follow my ideas.

    Yo can create the measures.

    Like this:

    Total = 
    COUNTROWS (
        FILTER (
            ALL ( 'Table' ),
            [Country ID] = SELECTEDVALUE ( 'Table'[Country ID] )
                && YEAR ( [Go Live] ) = YEAR ( MAX ( 'Table'[Go Live] ) )
                && MONTH ( [Go Live] ) = MONTH ( MAX ( 'Table'[Go Live] ) )
        )
    )
    
    3/4 total = 
    VAR a =
        EOMONTH ( MAX ( 'Table'[Go Live] ), 0 )
    RETURN
        COUNTROWS (
            FILTER (
                ALL ( 'Table' ),
                [Country ID] = SELECTEDVALUE ( 'Table'[Country ID] )
                    && [Go Live] >= a - 6
                    && [Go Live] <= a
            )
        )
    
    Percentage =
    DIVIDE ( [3/4 total], [Total] )
    

    You can put the country id and go live column in table visual.

     

    Did I answer your question? Please mark my reply as solution. Thank you very much.
    If not, please feel free to ask me.

    Best Regards,
    Community Support Team _ Janey

     

11 Replies

  • Anonymous , Have a column Week Year or week of month

     

    Year week = year([Date]) *100 + WEEKNUM([Date],2)

     

    or

    month week No = quotient(datediff([eomonth([date],-1)+1,[date],day),7)+1

     

    Then try a measure like

    MTD Sales = CALCULATE(lastnonblankvalue(date[Year Week],SUM(Sales[Sales Amount])),DATESMTD('Date'[Date]))

     

    Power BI — Month on Month with or Without Time Intelligence
    https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
    https://www.youtube.com/watch?v=6LUBbvcxtKA

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi im just trying that measure our however it doesnt seem to work so im trying the second option to get the last week.
    There is an error its picking up, would you be able to tell me if the format is incorrect

     

      • amitchandak's avatar
        amitchandak
        Icon for Super User rankSuper User

        Anonymous , One you are trying is a column.

         

        This one is measure

        MTD Sales = CALCULATE(lastnonblankvalue(date[Year Week],SUM(Sales[Sales Amount])),DATESMTD('Date'[Date]))