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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MPietrzyk
New Member

Combining columns in a single measure separated by date

Hello,

 

I do not think it's possible to do the way I want it, but I think I'd at least ask, as I cannot find a way to do it myself.

 

I want to calculate days spent on tasks per month. During the year there was a change in how those days are measured. Previously there was a single value that would encompass all days spent on a task. Now we have 12 values, each corresponding to days spent in a given month so that we could track days better. I also have start and end date.

 

Example for old and new data:

IDStart DayEnd DayDays spent oldDays spent JanuaryDays spent FebruaryDays spent MarchDays spent AprilDays spent MayDays spent JuneDays spent JulyDays spent AugustDays spent SeptemberDays spent OctoberDays spent NovemberDays spent December
101.03.202230.04.202210000000000000
204.05.202227.06.20220000073000000

 

For both tasks we know that someone has spent 10 days on it, but for the first case we don't know if it was 10 days in March or in April or what's the split. In this case we would assign all of the days to the month that the End date falls into.

In the second case we know the split between the months.

 

Is there a way to create a measure that would sum up all the days per month from both old system and new that we could visualize as days spent per month bar graph?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @MPietrzyk ,

 

Unpivot the [Days spent Months] columns in Query Editor.

Then create two calculated columns.

months = RIGHT('Table'[Attribute],LEN('Table'[Attribute])-11)

end_month = 'Table'[End day].[Month]

Result:

vjaywmsft_0-1658208604151.png

Then create a measure and create the visual:

Measure = SUM('Table'[Value])+CALCULATE(MAX('Table'[Days spent]),FILTER('Table','Table'[end_month]=SELECTEDVALUE('Table'[months])))

vjaywmsft_1-1658208785205.png

 

Best Regards,

Jay

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @MPietrzyk ,

 

Unpivot the [Days spent Months] columns in Query Editor.

Then create two calculated columns.

months = RIGHT('Table'[Attribute],LEN('Table'[Attribute])-11)

end_month = 'Table'[End day].[Month]

Result:

vjaywmsft_0-1658208604151.png

Then create a measure and create the visual:

Measure = SUM('Table'[Value])+CALCULATE(MAX('Table'[Days spent]),FILTER('Table','Table'[end_month]=SELECTEDVALUE('Table'[months])))

vjaywmsft_1-1658208785205.png

 

Best Regards,

Jay

Hi @Anonymous

 

thanks for the reply. It really helped me figure it out. What I did based on your suggestion is:

1. Unpivot [Days spent Months] columns making sure that I switch all nulls to 0

2. Created months column

months = SWITCH(MID('Table'[Attribute],11,3),"Jan", 1,"Feb", 2,"Mar", 3,"Apr", 4,"May", 5,"Jun", 6,"Jul", 7,"Aug", 8,"Sep", 9,"Oct", 10,"Nov", 11,"Dec", 12)

 

For some reason RIGHT did not work for me.

 

Then I've created a measure

Time_Spent = calculate(SUM('Table'[Value]),'ONT Cases PowerBI Dashboard'[months])+SUMX(DISTINCT('Table'[ID]), FIRSTNONBLANK('Table'[Days spent], 0))

 

I've changed it as above, because your measure summed by End Date only, even if the record had some days in [Days spent Months] columns

MPietrzyk
New Member

Hey @Greg_Deckler 

 

In the main post I've included an example of old and new data, but let me show what I would mean to do on some more examples.

 

Data consists of tasks with ID, Start Day, End Day, and 13 columns regarding the days it took to complete a task. Days Spent is an old measure that only keeps the value of the days and we have no idea if those days were split between months or not so we use End Day to decide. I.e. Days Spent is 5 and End Day is 06.06.2022 -> that means that the task took 5 days in June (even though in real life it might have been 4 days in May and 1 in June). Rest of the columns will be empty in this case

 

New data has the days split between other 12 columns, each for seperate month, and 0 in Days Spent as it's an old measure. I.e. Start and End Day don't matter anymore we only look at for example 4 days in Days Spent May and 1 Days Spent June.

 

Data table might look like this:

IDStart dayEnd dayDays spentDays spent JanuaryDays spent FebruaryDays spent MarchDays spent AprilDays spent MayDays spent JuneDays spent JulyDays spent AugustDays spent SeptemberDays spent OctoberDays spent NovemberDays spent December
102.02.202102.03.20215000000000000
208.02.202119.04.20215000000000000
301.03.202112.09.20219000000000000
416.03.202118.07.20214000000000000
505.06.202118.09.20212000000000000
629.09.202112.12.20210000000000034
714.10.202124.12.20210000000000160
805.11.202109.11.20210000000000040
906.12.202126.12.202100000000000010
1016.12.202118.12.20210000000000001

 

I want to create a measure that will combine old and new days spent measure in a single measure that I can plot per month. The result for the data in the table would look like this:

Picture1.png

Greg_Deckler
Community Champion
Community Champion

@MPietrzyk Probably possible but would need to understand the source data better. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.