cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Frequent Visitor

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Counting columns on a visual - measure

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])

Capture12.JPGCapture13.JPG

https://qiuyunus-my.sharepoint.com/:u:/g/personal/admin_qiuyunus_onmicrosoft_com/ESm5YDbrWsBFspfllCy...

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.

View solution in original post

6 REPLIES 6
Highlighted
Super User IV
Super User IV

Re: Counting columns on a visual - measure

@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.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Highlighted
Super User II
Super User II

Re: Counting columns on a visual - measure

@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.

Did I answer your question? Mark my post as a solution.Appreciate your Kudos!
Proud a to be a Datanaut!
Thanks and BR
Ryan
Highlighted
Community Support
Community Support

Re: Counting columns on a visual - measure

Hi @campelliann 

Could you share an example?

 

Best Regards

Maggie

Highlighted
Frequent Visitor

Re: Counting columns on a visual - measure

@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.

 

countingrows1.pngcountingrows2.png

Highlighted
Community Support
Community Support

Re: Counting columns on a visual - measure

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])

Capture12.JPGCapture13.JPG

https://qiuyunus-my.sharepoint.com/:u:/g/personal/admin_qiuyunus_onmicrosoft_com/ESm5YDbrWsBFspfllCy...

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.

View solution in original post

Highlighted
Frequent Visitor

Re: Counting columns on a visual - measure

Still a newbie here. It was not that hard 🙂

 

Many thanks!

Helpful resources

Announcements
Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.

Community Conference

Power Platform Community Conference

Check out the on demand sessions that are available now!

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Tech Marathon

Maratón de Soluciones de Negocio Microsoft

Una semana de contenido con +100 sesiones educativas, consultorios, +10 workshops Premium, Hackaton, EXPO, Networking Hall y mucho más!

Top Solution Authors
Top Kudoed Authors