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.
Hi,
I have a dataset with customer, monthly payment amount, next payment date, and final pmt date. Any way in M or DAX to "expand" the table such that each monthly pmt will become its own row? For example, I have a customer that owes 20 more payments of $1000 and that currently sits in one row with start date = end of this month, end date = EOM + 20. How do I expand that so that said customer has 20 rows (with each monthly pmt date in its own row), plus all other customers' row are expanded as well? For example, if I have 100 customers with 20 motns each left, resulting table would have 2,000 rows.
Ultimately looking to model cash flow based on monthly totals from this table. I will relate to calendar table w/end of month values and calc IRR, etc.
Thanks in advance!
Hi.
There is one simple method to solve the problem.
In Power Query Editor click Add Column tab - Custom Column (Start_Date and End_Date must be 'data' type).
Click Add Column tab > Custom Column and add the =expression {Number.From([Start_date])..Number.From([End_date])}
Two dots will generate a list from Start_date and End_date.
Extend created column Date with “Expand to New Rows”. Change extracted values to Data type.
The result table will be look like this.
Hope it will help you and others with the same problem.
Hi @jl20
If you've fixed the issue on your own please kindly share your solution. if the above posts help, please kindly mark it as a solution to help others find it more quickly. If not, please kindly elaborate more. thanks!
Hi @jl20 ,
You can do this in DAX by creating the date table and measure, then a expanded table:
Calculated Table:
Date =
ADDCOLUMNS (
CALENDAR (
MINX ( Payments, Payments[Start Date] ),
MAXX ( Payments, Payments[End Date] )
),
"Month", DATE ( YEAR ( [Date] ), MONTH ( [Date] ), 1 )
)
Calculated Table:
Months = values('Date'[Month])
Measure:
Active Customers =
CALCULATE (
COUNT ( Payments[Customer] ),
FILTER (
Payments,
MIN ( Months[Month] ) >= MIN ( Payments[Start Date] )
&& MIN ( Months[Month] ) <= MAX ( Payments[End Date] )
)
)
Calculated Table:
Expand =
SUMMARIZECOLUMNS (
Months[Month],
Payments[Customer],
Payments[Monthly Payment],
Payments[Start Date],
Payments[End Date],
"Active", [Active Customers]
)
The key is not to make a relationship between the tables.
Respectfully,
Zoe Douglas (DataZoe)
Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/
@jl20 , done something similar in this file. See if this can help
https://www.dropbox.com/s/bqbei7b8qbq5xez/leavebetweendates.pbix?dl=0
This didn't seem to be what I was looking for.
@jl20 Did you see the new financial functions that came out in the latest release? I was wondering if they may solve your problem without needing to expand the table. More information on those are at these links:
https://powerbi.microsoft.com/en-us/blog/power-bi-desktop-july-2020-feature-summary/
https://docs.microsoft.com/en-us/dax/financial-functions-dax
Also, if you can elaborate on why the solutions proposed were not solving your question, I'd be happy to take another look.
Respectfully,
Zoe Douglas (DataZoe)
Follow me on LinkedIn at https://www.linkedin.com/in/zoedouglas-data
See my reports and blog at https://www.datazoepowerbi.com/
@jl20 try this code, start blank query and paste code in advanced editor
let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjIwMtA1MAQiJR04x8hAKTYWAA==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Start = _t, End = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Start", type date}, {"End", type date}}),
#"Added Custom" = Table.AddColumn(#"Changed Type", "Date", each {Number.From([Start])..Number.From([End] )}),
#"Expanded DateRange" = Table.ExpandListColumn(#"Added Custom", "Date"),
#"Changed Type1" = Table.TransformColumnTypes(#"Expanded DateRange",{{"Date", type date}})
in
#"Changed Type1"
Logic is in added custom column step, and then expand it and change the type to date. Start and End in custom column will be your date column.
I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!
⚡Visit us at https://perytus.com, your one-stop shop for Power BI related projects/training/consultancy.⚡
Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!
Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo
If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤
Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
108 | |
98 | |
78 | |
66 | |
53 |
User | Count |
---|---|
139 | |
100 | |
95 | |
85 | |
63 |