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
AnetaK
Helper V
Helper V

Running Total (based on project size)

Hello,

I need help in creating a Running Total measure, but what is important - it should be based on projects, not dates.
Usually, Running Total is created by date, we start in January and increase e.g. the sum of sales with each month.

Now I have to create this sum, but based on the size of the project (% share of costs in the total). First we take the largest project, then add a smaller and smaller one to it... The table has to show the 10 largest projects.

The table is also to be filtered by various filters, such as the date, so the project position cannot be set hard.
If, for example, each project was permanently assigned a rank (in PQ or a calculated column in DAX), then the filter will not work on this rank. The largest project in January may already be finalized in February and may not appear in the data from February at all.
Therefore, everything has to be dynamic.

 

Below is a table showing how it should look like.
Anyone have any idea how to come to this?

(P.S. Cost and Cost% are DAX measures).

 

AnetaK_0-1612260702072.png

 

1 REPLY 1
DataInsights
Super User
Super User

@AnetaK,

 

Try this solution.

 

1. Create measures:

 

Total Cost = SUM ( FactProject[Cost] )

Cost % = 
VAR vNumerator = [Total Cost]
VAR vDenominator =
    CALCULATE ( [Total Cost], ALLSELECTED () )
VAR vResult =
    DIVIDE ( vNumerator, vDenominator )
RETURN
    vResult

Running Total = 
VAR vTopNumProjects = 10
--get all projects and their Cost % per the slicers/filters
VAR vBaseTable =
    ADDCOLUMNS (
        SUMMARIZE ( ALLSELECTED ( FactProject ), FactProject[Project] ),
        "@Cost%", [Cost %]
    )
--get the top N projects
VAR vTopProjects =
    TOPN ( vTopNumProjects, vBaseTable, [@Cost%] )
--add rank to the top N projects
VAR vRankedProjects =
    ADDCOLUMNS ( vTopProjects, "@Rank", RANKX ( vTopProjects, [@Cost%],, DESC ) )
--get the current project in the visual
VAR vCurrentProject =
    MAX ( FactProject[Project] )
--get the row in vRankedProjects for the current project
VAR vCurrentProjectRow =
    FILTER ( vRankedProjects, FactProject[Project] = vCurrentProject )
--get the rank for the current project
VAR vCurrentRank =
    MAXX ( vCurrentProjectRow, [@Rank] )
--get the rows that have a rank <= the current project's rank
VAR vTargetRows =
    FILTER ( vRankedProjects, [@Rank] <= vCurrentRank )
VAR vResult =
    IF ( HASONEVALUE ( FactProject[Project] ), SUMX ( vTargetRows, [@Cost%] ), BLANK() )
RETURN
    vResult

 

2. Create visual. Set the following visual filter: [Running Total] > 0. Sort the visual by [Running Total], ascending.

 

DataInsights_0-1612723819345.png

 

DataInsights_2-1612723852355.png

 





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




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.

Top Solution Authors