Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
campelliann
Post Patron
Post Patron

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

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
v-juanli-msft
Community Support
Community Support

Hi @campelliann 

Could you share an example?

 

Best Regards

Maggie

@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

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.

Still a newbie here. It was not that hard 🙂

 

Many thanks!

ryan_mayu
Super User
Super User

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

Proud to be a Super User!




amitchandak
Super User
Super User

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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.