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
Anonymous
Not applicable

Monthly Percent in a Table

Hello everyone,

 

I´m having problems with a DAX calculation.

I need to calculate the % of hours that suppose every row per month and person and I have a table like this.

 

Captura.PNG

 

Any help?

Thanks.

1 ACCEPTED SOLUTION

Hi @Anonymous,

 

Could you try the formula below to see if it works in your scenario? Smiley Happy

 

Task % =
VAR currentMonth =
    MONTH ( MAX ( 'Table2'[Fecha de trabajo] ) )
VAR currentYear =
    YEAR ( MAX ( 'Table2'[Fecha de trabajo] ) )
VAR currentPerson =
    MAX ( 'Table2'[Id_Persona] )
VAR HoursInTask = CALCULATE ( SUM ( 'Table2'[Horas] ), ALLEXCEPT ( Table2, 'Table2'[Id_Proyecto] ) ) VAR AmountHoursPersonInAllTasks = CALCULATE ( SUM ( 'Table2'[Horas] ), FILTER ( ALL ( 'Table2' ), 'Table2'[Id_Persona] = currentPerson && ( MONTH ( 'Table2'[Fecha de trabajo] ) = currentMonth && YEAR ( 'Table2'[Fecha de trabajo] ) = currentYear ) ) ) RETURN DIVIDE ( HoursInTask, AmountHoursPersonInAllTasks )

 

Regards

View solution in original post

7 REPLIES 7
Phil_Seamark
Employee
Employee

Hi @Anonymous

 

Could you please post a mock up of what you expect your result to look like.  That will help us fill the gap.


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Hello @Phil_Seamark,

 

I need a formula that looks like:
Task% = [Hours in the task]/[Amount of worked Hours in the month of this person in all worked tasks]

 

Hi @Anonymous

 

This might be getting close

 

Task % = 
var HoursInTask = CALCULATE(SUM('Table2'[Horas]),ALLEXCEPT(Table2,'Table2'[Id_Proyecto]))
var AmountHoursPersonInAllTasks = 
			CALCULATE(
				SUM('Table2'[Horas]),
				FILTER(
					ALL('Table2'),
					MONTH('Table2'[Fecha de trabajo])= MONTH(MAX('Table2'[Fecha de trabajo]))
					&& YEAR('Table2'[Fecha de trabajo])= YEAR(MAX('Table2'[Fecha de trabajo]))
					))
RETURN DIVIDE(HoursInTask,AmountHoursPersonInAllTasks)

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Anonymous
Not applicable

Thanks for answer so quickly @Phil_Seamark,

 

Yes, I have a CalendarTable with month, year, ...

I proved your formula and didn't show me what I need. 

I think this part don't work fine. It sums all hours of all tasks that I have, the date filter in the part of ALL() don't work.

var AmountHoursPersonInAllTasks = 
			CALCULATE(
				SUM('Table2'[Horas]),
				FILTER(
					ALL('Table2'),
					MONTH('Table2'[Fecha de trabajo])= MONTH(MAX('Table2'[Fecha de trabajo]))
					&& YEAR('Table2'[Fecha de trabajo])= YEAR(MAX('Table2'[Fecha de trabajo]))
					))

 

Hi @Anonymous,

 

Could you try the formula below to see if it works in your scenario? Smiley Happy

 

Task % =
VAR currentMonth =
    MONTH ( MAX ( 'Table2'[Fecha de trabajo] ) )
VAR currentYear =
    YEAR ( MAX ( 'Table2'[Fecha de trabajo] ) )
VAR currentPerson =
    MAX ( 'Table2'[Id_Persona] )
VAR HoursInTask = CALCULATE ( SUM ( 'Table2'[Horas] ), ALLEXCEPT ( Table2, 'Table2'[Id_Proyecto] ) ) VAR AmountHoursPersonInAllTasks = CALCULATE ( SUM ( 'Table2'[Horas] ), FILTER ( ALL ( 'Table2' ), 'Table2'[Id_Persona] = currentPerson && ( MONTH ( 'Table2'[Fecha de trabajo] ) = currentMonth && YEAR ( 'Table2'[Fecha de trabajo] ) = currentYear ) ) ) RETURN DIVIDE ( HoursInTask, AmountHoursPersonInAllTasks )

 

Regards

Anonymous
Not applicable

Thanks @v-ljerr-msft,

Works great with little modifications.

Task % =
VAR currentMonth =
    MONTH ( 'Table2'[Fecha de trabajo] )
VAR currentYear =
    YEAR ( 'Table2'[Fecha de trabajo]  )
VAR currentPerson =
    ( 'Table2'[Id_Persona] )
VAR HoursInTask = SUM ( 'Table2'[Horas] ) VAR AmountHoursPersonInAllTasks = CALCULATE ( SUM ( 'Table2'[Horas] ), FILTER ( ALL ( 'Table2' ), 'Table2'[Id_Persona] = currentPerson && ( MONTH ( 'Table2'[Fecha de trabajo] ) = currentMonth && YEAR ( 'Table2'[Fecha de trabajo] ) = currentYear ) ) ) RETURN DIVIDE ( HoursInTask, AmountHoursPersonInAllTasks )

 

Hi @Anonymous

 

Do you have a Date Table that has a Month column?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

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.