I am new to PowerBi.
What I am trying to do is summarize an email marketing report for open, clicks with the exported data. The data looks like
| Campaign Name | Email Address | Event Type |
|:---------------: |:---------------------:| :--------: |
| Test Campaign | test#example.com | Open |
| Test Campaign | test#example.com | Open |
| Test Campaign | test123#example.com | Open |
| Test Campaign 2 | test#example.com | Open |
| Test Campaign 2 | test#example.com | Open |
| Test Campaign 2 | test1234#example.com | Open |
| Test Campaign 2 | test#example.com | Clicked |
| Test Campaign 2 | test#example.com | Clicked |
I want to calculate each event type that is unique for each email address and summarize it by the campaign name. There can be duplicate email address if someone opens email twice. And there are multiple different campaign names
I want PowerBI to be able to take the above data and summarize it as such with a measure formula :
Campaign Name
Open
Click
Test Campaign
2
0
Test Campaign 2
2
1
Any suggestions? I can't get it to summarize by campaign name.
Clicks = Calculate(DistinctCount('table'[column]),'table2 for event type'[event type] = "click"))
You can do it in DAX very quickly.
In PowerBI, you create two new measures:
Please note that I've used 'Table' as the table name, replace it with the actual name of your table.
'Table'[Open_Nb] =
CALCULATE(
DISTINCTCOUNT('Table'[Email Address ]),
'Table'[Event Type] = "Open"
)
and
'Table'[Clicked_Nb] =
CALCULATE(
DISTINCTCOUNT('Table'[Email Address ]),
'Table'[Event Type] = "Clicked"
)
Then you can use this table two ways. You can create a new Table visual and drag and drop :
Campaign Name
Measure Open_Nb
Measure Clicked_Nb
Or, directly as a new table with the expression :
ADDCOLUMNS(
SUMMARIZE(
'Table',
'Table'[Campaign Name ]
),
"Open",
'Table'[Open_Nb],
"Click",
'Table'[Clicked_Nb]
)
Related
I have a quite niche problem in regards to PowerBI slicer operations.
I wish to filter the data based on two different slicers.
For example I have two different slicers;
A list of categories, say Genre of Films; and
A list of all film directors
I wish to filter the data shown in the PowerBI report based on an OR condition between the two slicers.
For instance, I wish to filter based on all Horror films OR films directed by Quentin Tarantino. So this list would show all Horror films in my database and all films directed by Quentin Tarantino (that are not necessarily Horror films).
I presume that I will need to write some form of DAX code for this but through substantive searching I have not come across this particular problem.
Let me know if you need any further info.
Regards,
Josh
Let's suppose you have a table called IMDB like following
| tbl-IMDB |
|--------------------------|---------|----------------------|
| Name | Genre | Director |
|--------------------------|---------|----------------------|
| The Shawshank Redemption | Drama | Frank Darabont |
| The Godfather | Crime | Francis Ford Coppola |
| The Dark Knight | Action | Christopher Nolan |
| 12 Angry Men | Drama | Sidney Lumet |
| Schindler's List | History | Steven Spielberg |
| Pulp Fiction | Crime | Quentin Tarantino |
and two more disconnected table for slicers as following
| tbl-Director |
|----------------------|
| Director |
|----------------------|
| Frank Darabont |
| Francis Ford Coppola |
| Christopher Nolan |
| Sidney Lumet |
| Steven Spielberg |
| Quentin Tarantino |
|tbl-Genre|
|---------|
| Genre |
|---------|
| Drama |
| Crime |
| Action |
| History |
the data model looks like this
Now, if I understood your question correctly, when you select {Crime,Action} from Genre and {Sidney Lumet, Steven Spielberg} from Director it should return 5 instances; i.e. leaving only the first instance of -The Shawshank Redemption
In order to get there, first all the slicer combinations are needed to be taken into account and what they can do the table.
a. all the slicer values are selected in Director and Genre slicer - DAX to return the full table.
b. none of the slicer values are selected in Director and Genre slicer - DAX to return the full table because the default behavior of DAX is to return the full table if nothing is selected in the slicer.
c. partial values are selected in Genere and nothing/everything is selected in Director and vice versa -
DAX is to return the full table for example, if Drama is selected (2 instances) + nothing/everything is selected in Director (6 instnaces) -> total 6 instances
d. partial values are selected in both Genere and Director - DAX to return the addition of the instances according to the slicer selection - ;e,g. Drama=2+Sideney Lumet=1 => total 3 instances
The above logic can be incorporated in a DAX measure like following
Measure =
VAR _genre = --- what are the genres selected from Genere Slicer and find them in IMDB tbl
MAXX (
FILTER ( IMDB, IMDB[Genre] IN ALLSELECTED ( Genre[Genre] ) ),
IMDB[Genre]
)
VAR _director = --- what are the directors selected from Director Slicer and find them in IMDB tbl
MAXX (
FILTER ( IMDB, IMDB[Director] IN ALLSELECTED ( Director[Director] ) ),
IMDB[Director]
)
VAR _genreCountALL = -- what are the total count of genere from Genre tbl regardless of the slicer seletion
CALCULATE ( COUNT ( Genre[Genre] ), ALL ( Genre ) )
VAR _directorCountALL = -- what are the total count of director from Director tbl regardless of the slicer seletion
CALCULATE ( COUNT ( Director[Director] ), ALL ( Director ) )
VAR _genreCountSELECT = -- what are the total count of genere from Genre tbl according to slicer seletion
COUNT ( Genre[Genre] )
VAR _directorCountSELECT = -- what are the total count of director from Director tbl according to slicer seletion
COUNT ( Director[Director] )
VAR _slice = --- if Genere and/Director slicer are both selected then return the max else in every other instances it is a full tbl
SWITCH (
TRUE (),
_genreCountALL <> _genreCountSELECT
&& _directorCountALL <> _directorCountSELECT,
CALCULATE (
MAX ( IMDB[Name] ),
FILTER ( IMDB, IMDB[Director] IN { _director } || IMDB[Genre] IN { _genre } )
),
CALCULATE ( MAX ( IMDB[Name] ) )
)
RETURN
_slice
and put a visual level filter like following
The measure produces following
nothing is selected - returns full table
partial values are selected in only one slicer- returns full table
partial values are selected in all available slicers - returns the sliced table
below is my query. Kindly help.
I have a table visual in Power BI as below so when I select request id '1' all other visuals in that report page shows the the corresponding data. I have a slicer called 'Calendar date' where it shows date from 2019 to 2022 and user can select whatever dates they want.
My question is when user selects a request id from the below table visual, the Calendar date slicer must automatically select 'Request Start date. Is this possible?
Request id| Request Name| Request start date| Request End date
---------------------------------------------------------------
1 | A | DD/MM/2020 | DD/MM/2021
2 | B | DD/MM/2021 | DD/MM/2022
3 | C | DD/MM/2022 | DD/MM/2023
4 | D | DD/MM/2019 | DD/MM/2019
5 | E | DD/MM/2018 | DD/MM/2018
This feature is currently not possible in Power BI. Lets hope in future this will be available.
I have the following columns in my dataset:
_____________________________________________________________________________________
| ... |Start Date| Start Time | End Date | End Time | Production Start Date | ... |
|_____|__________|____________|____________|____________|_______________________|_____|
| ... | 01022020 | 180000 | 02022020 | 190000 | 01022020 | ... |
| | | | | | | |
Sometimes the Start Date + Start Time etc. values are blank but the Production Start Date values are always populated.
When the Start Date is empty (NULL), for example, I want my dataset (or ideally, graph) to read the Production Start Date.
How can I achieve this in Power BI?
I know I can make a conditional column, then within that, determine which column to read data from but is there any way to add a condition to the existing Start Date column? I couldn't see such an option in the context menu or subsequent ribbon options.
Is my only option to create a custom conditional column instead?
As #Andrey Nikolov mentioned in the comments, the only ways you can achieve this is to:
1 Create a calculated DAX column.
2 Create a custom column in query mode (M).
3 Edit the original source table.
doug
I have a table, let's call it Products with columns:
Id
ProductId
Version
some other columns…
Id column is the primary key, and ProductId groups rows. Now I want to view distinct values of ProductId where Version is highest.
I.e. From data set:
Id | ProductId | Version | ...
100 | 1 | 0 | ...
101 | 2 | 0 | ...
102 | 2 | 1 | ...
103 | 2 | 2 | ...
I need to get:
Id | ProductId | Version | ...
100 | 1 | 0 | ...
103 | 2 | 2 | ...
In SQL I would write:
SELECT Id, ProductId, Version, OtherColumns
FROM Products p1
WHERE NOT EXISTS
(SELECT 1
FROM Products p2
WHERE p2.ProductId = p1.ProductId
AND p2.Version > p1.Version)
But I have no idea how to express this in DAX. Is this approach with subqueries inapplicable in PowerBI?
Another approach is to first construct a virtual table of product_ids and their latest versions, and then use this table to filter the original table:
EVALUATE
VAR Latest_Product_Versions =
ADDCOLUMNS(
VALUES('Product'[Product_Id]),
"Latest Version", CALCULATE(MAX('Product'[Version])))
RETURN
CALCULATETABLE(
'Product',
TREATAS(Latest_Product_Versions, 'Product'[Product_Id], 'Product'[Version]))
Result:
The benefit of this approach is optimal query execution plan.
You can use SUMMARIZECOLUMNS to group ProductId and MAX Version.
Then use ADDCOLUMNS to add the corresponding Id number(s), using a filter on the Products table for the matching ProductId and Version. I've used CONCATENATEX here, so that if multiple Id values have the same Product / MAX Version combination, all Id values will be returned, as a list.
EVALUATE
ADDCOLUMNS (
SUMMARIZECOLUMNS (
Products[ProductId],
"#Max Version",
MAX ( Products[Version] )
),
"#Max Version Id",
CONCATENATEX (
FILTER (
Products,
Products[Version] = [#Max Version] && Products[ProductId] = EARLIER ( Products[ProductId] )
),
Products[Id],
","
)
)
I have two tables like the fallowing:
On server:
| Orders Table | OrderDetails Table
-------------------------------------------------------------------------------------
| Id | Id
| OrderDate | OrderId
| ServerName | Product
| Quantity
On client:
| Orders Table | OrderDetails Table
-------------------------------------------------------------------------------------
| Id | Id
| OrderDate | OrderId
| Product
| Quantity
| ClientName
I need to sync the [Server].[Orders Table].[ServerName] to [Client].[OrderDetails Table].[ClientName]
The Question:
What is the true and efficient way of making it?
I know Deprovisioning and provisioning with different config, is one way of doing it.
So I just wanna know the correct way.
Thanks.
EDIT :
Other columns of each table should sync normally ([Server].[Orders Table].[Id] to [Client].[Orders Table].[Id] ...).
And mapping strategy sometimes changes based on the row of data (which which is sending/receiving).
Sync Fx is not an ETL tool. simply put, it's DB sync is per table.
if you really want to force it to do what you want, you can simply intercept ChangesSelected event for the OrderDetails table, lookup the extra column from the other table and then dynamically add the column to the dataset before it gets applied on the other side.
see this link on how to manipulate the change dataset