Forum Discussion
FILTERED SUM Over Many Rows
I would first create two new dimension tables: Accounts and Stores.
Since you're using SQL, it should be something akin to
SELECT DISTINCT accountnumber AS "Account Number" FROM TABLE
SELECT DISTINCT store# AS "Store #" FROM TABLE
Then, create a relationship between these tables and the appropriate columns in the fact table above.
Next, as you suspected, I would reccomend transforming the fact table.
- Rename the colums: janbalance = 1, febbalance = 2, etc.
- Unpivot the monthly balance columns. We'll call their numbers "Month" and their value "Balance".
- Create a date foreign key for each row.
In powerQuery, you can do something like:
= Table.AddColumn(#"Changed Type", "Year-Month", each Text.Combine({Text.From([Month], "en-US"), "/1/", DateTime.ToText([Last day of the year], "yyyy")}), type date)
- I'd create a calendar table with month, year, year-month, etc;.
Then, connect it to the "Year-Month" column we've just created.
Now you're set!
SUM the Balance column, while using the accounts, stores and calendar tables we created (instead of the columns in the fact table).
I hope it works!
- Anonymous4 years agoNot applicable
First, thank you. Rewriting my SQL query and performing some transformations helped shape the data. So for my delayed appreciation as many other challenges come up during this project that required additional time.