Forum Discussion

campelliann's avatar
campelliann
Post Patron
6 years ago
Solved

Counting columns on a visual - measure

Hi friends,

 

I have a table (visual) that can have a variable amount of columns - depending on the filter the user applied. I would like to create a measure which is 40*"number of current columns in the visual".

 

Can you help?

  • Hi campelliann 

    Create a date table and create a relationship with your main table.

    Date =
    ADDCOLUMNS (
        CALENDARAUTO (),
        "year", YEAR ( [Date] ),
        "month", MONTH ( [Date] ),
        "week", WEEKNUM ( [Date], 2 ),
        "year-week", YEAR ( [Date] ) & "-" & "week"
            & WEEKNUM ( [Date], 2 )
    )
    

    Use the [week] from the date table into a slicer.

    Then create measures

    actual registered = SUM('Table'[registerd hour])
    
    discount weeks = CALCULATE(DISTINCTCOUNT('Date'[year-week]),ALLSELECTED('Date'))
    
    still need = DISTINCTCOUNT('Table'[name id])*40*[discount weeks]-SUMX('Table',[actual registered])

    https://qiuyunus-my.sharepoint.com/:u:/g/personal/admin_qiuyunus_onmicrosoft_com/ESm5YDbrWsBFspfllCyZ_9wBoxeX3psErwzSPbs7pxdwJA?e=U1YWr7

    download my pbix file for more details.

     

    Best Regards
    Maggie
    Community Support Team _ Maggie Li
    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

6 Replies

  • campelliann , Not sure I got it. typically number measures are constant in a visual.

    The information you have provided is not making the problem clear to me. Can you please explain with an example.

    Appreciate your Kudos.

  • campelliann 

     

    I think you need to create a new table based on the logic of creating that visual table. Then you countrows of the new table.

     

    What's more, you need to provide more details on your questions.

     

    Hope this is helpfu.

    • campelliann's avatar
      campelliann
      Post Patron

      v-juanli-msft  Maggie,  amitchandak , Thanks in advance for your help.

       

      This is basically a timesheet control to assure everyone registers 40h per week. I select a week (e.g. 5 june) and calculate a measure for the hours yet to be registered - graph at the right.  I want the formula to be Hours missing = Number of people x 40 x number of weeks selected - total hours registered in the week/weeks selected

       

      If I select the week 5 june alone, or 12 june alone, the formula works. But if I select both weeks (or more) it doesnt - because the measure i created is for 40 hours per person (doesnt take into account the number of weeks/columns in the filter).

       

      Suming up: if the filter is on 1 week, each person must register 40 h. If in two weeks 80 h etc.

       

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

        Hi campelliann 

        Create a date table and create a relationship with your main table.

        Date =
        ADDCOLUMNS (
            CALENDARAUTO (),
            "year", YEAR ( [Date] ),
            "month", MONTH ( [Date] ),
            "week", WEEKNUM ( [Date], 2 ),
            "year-week", YEAR ( [Date] ) & "-" & "week"
                & WEEKNUM ( [Date], 2 )
        )
        

        Use the [week] from the date table into a slicer.

        Then create measures

        actual registered = SUM('Table'[registerd hour])
        
        discount weeks = CALCULATE(DISTINCTCOUNT('Date'[year-week]),ALLSELECTED('Date'))
        
        still need = DISTINCTCOUNT('Table'[name id])*40*[discount weeks]-SUMX('Table',[actual registered])

        https://qiuyunus-my.sharepoint.com/:u:/g/personal/admin_qiuyunus_onmicrosoft_com/ESm5YDbrWsBFspfllCyZ_9wBoxeX3psErwzSPbs7pxdwJA?e=U1YWr7

        download my pbix file for more details.

         

        Best Regards
        Maggie
        Community Support Team _ Maggie Li
        If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.