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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Yonko
Helper I
Helper I

How to get total value?

Hi there. This is my problem - there is a table with project names, tasks and time (for simplicity there is only 1 project). Each project may have different tasks, and each tasks will take different time to complete. There is also an entry "total" which has to be the sum of time of all tasks for every single project. Project and tasks are entries from one table, and time from another - in that another table there is no entry "total", only tasks, and i can't add it, that's why i need to sum it here somehow, which i can't do, that why i'll be glad if you'll help me. I guess that to complete it we need to create another column (or measure), with condition that if task = "total" then we need to sum all time for each project, and if not we just need to take time without changing.

Yonko_0-1664034736264.png

In the end it should be like this:

Yonko_1-1664034816337.png

 

 

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Yonko ,

 

Based on your description, I have creeated a simple sample:

vjianbolimsft_0-1664162181122.png

vjianbolimsft_1-1664162191728.png

vjianbolimsft_2-1664162203224.png

Please try:

 

Time = 
VAR _a =
    SUM ( 'Table (2)'[Time] )
VAR _b =
    SELECTCOLUMNS (
        FILTER ( ALL ( 'Table' ), [Project] = MAX ( 'Table'[Project] ) ),
        "Task", [Task]
    )
VAR _c =
    SUMX ( FILTER ( ALL ( 'Table (2)' ), [Task] IN _b ), [Time] )
RETURN
    IF ( MAX ( 'Table'[Task] ) = "Total", _c, _a )

 

Final output:

vjianbolimsft_3-1664169351353.png

Best Regards,

Jianbo 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-jianboli-msft
Community Support
Community Support

Hi @Yonko ,

 

Based on your description, I have creeated a simple sample:

vjianbolimsft_0-1664162181122.png

vjianbolimsft_1-1664162191728.png

vjianbolimsft_2-1664162203224.png

Please try:

 

Time = 
VAR _a =
    SUM ( 'Table (2)'[Time] )
VAR _b =
    SELECTCOLUMNS (
        FILTER ( ALL ( 'Table' ), [Project] = MAX ( 'Table'[Project] ) ),
        "Task", [Task]
    )
VAR _c =
    SUMX ( FILTER ( ALL ( 'Table (2)' ), [Task] IN _b ), [Time] )
RETURN
    IF ( MAX ( 'Table'[Task] ) = "Total", _c, _a )

 

Final output:

vjianbolimsft_3-1664169351353.png

Best Regards,

Jianbo Li

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

tamerj1
Super User
Super User

Hi @Yonko 

please try

Time Measure =
VAR CurrentTask =
    SELECTEDVALUE ( Table1[Task] )
VAR NormalValue =
    SUM ( Table2[Time] )
VAR TotalValue =
    CALCULATE ( SUM ( Table2[Time] ), ALL ( Table1[Task] ) )
RETURN
    IF ( CurrentTask = "Total", TotalValue, NormalValue )

@tamerj1 The problem in your formula happens with TotalValue = it should return sum of values (8), but instead it returns values without changing (3 and 5). If it somehow will return 8 it will work, and i tried different approaches but not succeeded. Any suggestions?
@Anonymous It also returns the same values, not sum of them. I guess it happens because it filtered not only by projects, but also by tasks, so it's granularity moves from project to task and it's not working. I don't know how to fix it sadly 😞

Anonymous
Not applicable

Maybe you can share an example file ?

@Yonko 
It should work unless the filter context a more complex than described.

Anonymous
Not applicable

Your Time column is a measure?
If not create a measure : MeasureNameOfTime = Sum(Table[Time])
Try
 
Measure Name =
SUMX(ADDCOLUMNS(
SUMMARIZE(
TableName, TableName[Project] , TableName[Task])
,"Invented Column Name",
CALCULATE(
[MeasureNameOfTime])),[Invented Column Name])

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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

Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Top Kudoed Authors