SSAS/ PowerBi / DAX - How to combine multiplie colunms in one - powerbi

I am using Power Bi with SSAS Tubular Model.
I have a table that causes duplication due to multiple managers on a project.
Projekt Manager Revenue
Car-Sales Bob 200k
Car-Sales Chris 200k
Car-Sales Tina 200k
I want to combine these Manager entries to one entry with commas.
Projekt Manager Revenue
Car-Sales Bob,Chris,Tina 200k
How do I write this in DAX?

This should be done upstream in your data shaping stage but if you're stuck with DAX, then create a new table as follows:
Table 2 = ADDCOLUMNS( SUMMARIZE('Table', 'Table'[Projekt], 'Table'[Revenue]), "Manager", CONCATENATEX('Table', 'Table'[Manager], ","))

Related

Power BI - If a date is between 2 dates using relationships

I am trying to determine if a date is between 2 other dates that are is 2 different tables using
Power BI.
For simplicity, here is the model that I have :
TableB is the bridge table between TableA and TableC.
I have an inactive relationship between tableA and TableC.
I have tried the following logic to check if TableC.createdDate is between TableA.startDate and TableA.endDate :
Create a calculated column in TableC, but I was not able to access columns in TableA
Create a calculated column in TableB, but I was having blank results, which is not suppose to happen
Have you tried using USERELATIONSHIP to force your calculated column to use the inactive relationship to TableA? documentation link
So something like
CALCULATE(
{{created date is >start and <end}},
USERELATIONSHIP('TableA'[TableB_ID],'TableC'[TableB_ID]
)

How can I aggregate one column in one table after applying a filter based on a column in another table in Power BI?

I am trying to do something in Power BI which is trivial in SQL. If I have two tables like this.
Table Accounts
Account
Closing
A
01-01-2021
B
01-02-2021
Table Payments
Account
Date
Amount
A
01-01-2020
10
A
01-03-2021
20
A
01-04-2021
30
B
01-01-2005
10
B
01-03-2021
20
B
01-04-2021
30
I would like to create a measure that aggregates the transactions of the accounts if they happened after the closing. In SQL it would be like this
select a.account, sum(b.amount)
from
accounts a inner join
payments b on a.account = b.account
where
b.date > a.closing
group
by a.account
In Power BI, I can easily build the aggregate without the where clause just by creating a measure in account with value SUM(Payments[Amount]). I tried to add the filter command in the sum, but Accounts[Closing] does not show as an available column when I write the filter.
I already spent quite some time looking for solutions and I didn't find anything satisfactory. Of course I can solve this by doing the aggregation at SQL level but there are other things that wouldn't work very well in my original model.
Thanks very much in advance and kind regards
If your both tables are properly related using Account column, you can use this below Measure for your purpose-
total =
CALCULATE(
sum(Payments[Amount]),
FILTER(
Payments,
Payments[Date] > MIN(Accounts[Closing])
)
)
Output will be as below-

Trying to combines multiple employees' timesheet tables using power query for Power BI report

I am having trouble cleaning the data from timesheet tables from multiple employees.
The timesheets are attendance records and I want to import the data to a single dataset into Power bi for analysis.
The time entries are separated by each employee's Staff ID and dates into a table and there are 78 tables for each employee.
I have tried to use transpose, pivoting the tables, and splitting column 1 with the delimiter of staff ID: but unable to get it to work.
Appreciate the help.

Power BI DAX data from 2 tables

I have 2 tables see image
And I want to get total revenue for Store ABC only for product "ID1" so in this simple tables the final Revenue should be 251.
So I should filter only "ABC" in first table and filter only "ID1" in the second and then add column "Revenue" to the first table with the key "email" and then SUM revenue, but I got completely lost how to write it in DAX
Any suggestions?
Thanks
Lukas

Power BI - Select Slicer Date Between 2 Columns

Hopefully a quick explanation of what I am hoping to accomplish followed by the approach we've been working on for over a year.
Desired Result
I have a table of SCD values with two columns, SCD_Valid_From and SCD_Valid_To. Is there a way to join a date table in my model (or simply use a slicer without a join) in order to be able to choose a specific date that is in between the two SCD columns and have that row of data returned?
Original Table
ID | SCD_Valid_From | SCR_Valid_To | Cost
1 2020-08-01 2020-08-03 5.00
Slicer date chosen is 2020-08-02. I would like this ID=1 record to be returned.
What We've Attempted So Far
We had a consultant come in and help us get Power BI launched last year. His solution was to create an expansion table that would contain a row for every ID/Date combination.
Expanded Original Table
ID | SCD_Valid_Date | Cost
1 2020-08-01 5.00
1 2020-08-02 5.00
1 2020-08-03 5.00
This was happening originally on the Power BI side, and we would use incremental refresh to control how much of this table was getting pushed each day. Long story short, this was extremely inefficient and made the refresh too slow to be effective - for 5 years' worth of data, we would need over 2000 rows per ID just to be able to select a dimensional record.
Is there a way to use a slicer where Power BI can select the records where that selected date falls between dates in two columns of a table?
Let me explain a workaround and I hope this will help you to solve your issue. Let me guess you have below 2 tables-
"Dates" table with column "Date" from where you are generating the date slicer.
"your_main_table" with with column "scd_valid_from" and "scd_valid_to".
Step-1: If you do not have relation between table "Dates" and "your_main_table", this is fine as other wise you have to create a new table like "Dates2". For this work around, you can not have relation between those tables.
In case you have already relation established between those tables, create a new custom table with this below code-
Dates2 =
SELECTCOLUMNS(
Dates,
"Date", Dates[Date]
)
From here, I will consider "Dates2" as source of your Date slicer. But if you have "Date" table with no relation with table "your_main_table", just consider "Dates" in place of "Dates2" in below measures creation. Now, Create these following 4 measures in your table "your_main_table"
1.
date_from_current_row = max(join_using_date_range[SCD_Valid_From])
2.
date_to_current_row = max(join_using_date_range[SCD_Valid_to])
3.
date_selected_in_slicer = SELECTEDVALUE(Dates2[Date])
4.
show_hide_row =
if(
[date_selected_in_slicer] >= [date_from_current_row]
&& [date_selected_in_slicer] <= [date_to_current_row]
,
1,
0
)
Now you have all instruments ready for play. Create your visual using columns from the table "your_main_table"
Final Step: Now just add a visual level filter with the measure "show_hide_row" and set value will show only when "show_hide_row = 1".
The final output will be something like below image-