100% found this document useful (1 vote)
228 views39 pages

Advanced DAX - Dynamic Segmentation, Time Comparisons, Cross Sell and Averages - Power BI Experience

This document discusses advanced DAX concepts for dynamic segmentation, time comparisons, cross sell analysis, and averages. It provides examples and steps to create measures in Power BI to: [1] Compare revenue and margin between years (YoY analysis); [2] Analyze cross sell opportunities; [3] Analyze averages among categories. Measures are created to dynamically segment revenue by growth categories defined in a parameter table. Visuals like charts and scatter plots are used to showcase the analyses.

Uploaded by

Denisa Secuiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
228 views39 pages

Advanced DAX - Dynamic Segmentation, Time Comparisons, Cross Sell and Averages - Power BI Experience

This document discusses advanced DAX concepts for dynamic segmentation, time comparisons, cross sell analysis, and averages. It provides examples and steps to create measures in Power BI to: [1] Compare revenue and margin between years (YoY analysis); [2] Analyze cross sell opportunities; [3] Analyze averages among categories. Measures are created to dynamically segment revenue by growth categories defined in a parameter table. Visuals like charts and scatter plots are used to showcase the analyses.

Uploaded by

Denisa Secuiu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

(https://po

avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Advanced DAX: Dynamic Segmentation,


Time Comparisons, Cross Sell and
Averages
July 28, 2020(https://powerbiexperience.com/en/2020/07/28/) , 12:22 am
, Power BI (https://powerbiexperience.com/en/categoria/powerbi/)

Leonardo Karpinski
Power BI Master and Microsoft Certi ed Trainer, owner of the Power BI Experience. Graduated
more than 20,000 students and participated in extensive projects for global companies.


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Hey guys, how are you?!

Today our post refers to Live #27 of the Master!!!

Before I start, I’d like to ask a few questions. Have you ever had problems with analysis

used to compare current results with last year or other weeks? What about problems

with analysis where you have to compare speci c averages with the total? Or have you

ever wondered what a cross sell analysis is?

I often receive questions on my social networks regarding these topics, and the subject

for our Live #27!

So, stick around and follow up until the end that you will be good at these advanced

DAX themes:

YoY Analysis of Revenue and Margin (comparison between subsequent years)

Cross sell

Analysis among averages

Analysis: YoY Revenue


I will do an analysis evaluating the sales revenue measure of a certain company

comparing the current year with the previous one.

Tip:

Remember that by “current” in Power BI depends on the evaluation context. Imagine

that we have data from 2017 to 2019 in our database. And on the page where we will

do the analysis we lter the year 2018. Then, our “current” context will be 2018.

First, let’s create the Revenue measure:

Faturamento =

SUMX ( fVendas, fVendas[QtdItens] * fVendas[ValorUnitario] ) 


/
(https://po
 and also a data Portuguêsavancado-
Along with it we will make our rst visual with invoicing by category
comparac
segmentation per year: medias/)
(https://powerbiexperience.com/)

Figure 1: Revenue Chart by Category

Figure 2: Data segmentation per year



/
(https://po
Stages: avancado-
 Português
comparac
1. In "Visualizações" select "Tabela" → Format the space as image
medias/)
(https://powerbiexperience.com/)
2. In "Visualizações" select "Segmentações" → Format the space as ima

We need 3 other measures to continue our analysis:

Faturamento LY =

CALCULATE ( [Faturamento], SAMEPERIODLASTYEAR ( dCalendario[Data]

) )

Faturamento YoY =

[Faturamento] – [Faturamento LY]

Faturamento YoY % =

DIVIDE ( [Faturamento YoY], [Faturamento LY] )

The abbreviations LY and YoY, come from Last Year (previous year) and Year over

Year (year over year).

A question….did you notice anything di erent in the 4 measures? Pay attention to the

dividers used within the functions!

And then, do you understand? I am using “,” instead of “;”. This was an option that

came in one of the last Power BI updates. And for those who follow me, they know

that I intend to promote my work in other countries! So, I’ve already started to adapt.

Thinking about the future…

Well, with these measures we have already made some progress with the analysis in

our chart for the Year 2018:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 3: Analysis Chart

Stages:

Add the new measures in the "Valores" space.

S catter Plot
This is one I don’t use so much, but I started to focus on using it more often, because it

helps a lot the user to understand and see the whole scenarios.

The rst step is to create the graph with the information we already have:

Figure 4: Scatter Plot


/
(https://po
Stages: avancado-
 Português
comparac
In "Visualizações" select "Gráfico de dispersão" → Format the space a
medias/)
(https://powerbiexperience.com/)

It helps a lot if we put a parameter for the graphic subtitle that di ers if the growth

was high, low or negative, for example.

This is possible, but before we add this element to the view we need an auxiliary table

with the limits of this parameter.

Figure 5: Creation of a segmentation chart

Stages:

In "Página Inicial" select "Inserir dados" → Fill in the table


/
Important: (https://po
avancado-
When using limits in measures you have to be very careful where you are going to usePortuguêscomparac
medias/)
smaller (<), larger (>) and equal (=). A lot of people make this mistake and complicate
(https://powerbiexperience.com/)

once you have to calculate the measurement.

The next measure we will create is the one that makes the calculation of the

segmented revenue by our growth parameter:

Faturamento por Categoria =

CALCULATE (

[Faturamento],

FILTER (

VALUES ( dCliente[Categoria] ),

[Faturamento YoY %] >= MIN ( SegmentoCrescimento[LimInf]

&& [Faturamento YoY %] < MAX ( SegmentoCrescimento[Li

mSup] )

Along with it we have the dynamic segmentation of the revenue per growth! Let’s see

if it works!? For that I will create a visual with the segmentation chart and with the

revenue measures data with and without the lter:

Figure 6: Chart with growth analysis



/
(https://po
Stages: avancado-
 Português
comparac
1. Create the Revenue measure by Category
medias/)
(https://powerbiexperience.com/)
2. In "Visualizações" select "Tabela" → Set up the space according to

See that if we don’t apply the lter to create this virtual relationship in the measure

the revenue calculation doesn’t comprehend the growth context!

By doing so, we can improve our scatter plot by changing the X-axis measurement and

adding the legend:

Figure 7: Scatterplot Change

Another cool design that helps you understand the revenue is the stacked bar chart!

Let’s create it as follows:


/
Figure 8: Stacked bar chart
(https://po
avancado-

To visualize the representation of our turnover by category and growth type, we will
Português
comparac
medias/)
(https://powerbiexperience.com/)
create a clustered column chart:

Figure 9: Clustered column chart

Stages:

1. In "Visualizações" select "Gráfico de dispersão" → Set up the spac

2. In "Visualizações" select "Gráfico de barras empilhado" → Set up t

2. In "Visualizações" select "Gráfico de colunas clusterizado" → Set

Besides, imagine that the user wants a quickly view only the negative categories. What

could we do to build this into our design!? If you answered data/ lter segmentation,

you got it right! Let’s put it together:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 10: Data segmentation per growth

Stage:

1. In "Visualizações" select "Segmentação de dados" → Set up the spac

I told you this classi cation is dynamic! Well, and then you can ask “Leo, why is this

classi cation dynamic!? I answer you! Because if you add lters and change contexts

on the page the visuals will interact with this new de nition! So, it’s not static….

For example, we will apply a lter for the “Sugar” group on the page:

Figure 11: “Sugar” group segmentation


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 12: Result of the applied lter

Stages:

1. In "Visualizações" select "Segmentação de dados" → Set up the spac

2. Show results variation

See how much the stacked bar chart values have changed!

To nish our page, we will place a card indicating our summarized revenue variation:

Figure 13: Multiple-line card


/
(https://po
Stage: avancado-
 Português
comparac
In "Visualizações" select "Multiple-line card" → Set up the space acc
medias/)
(https://powerbiexperience.com/)

The result of our rst page of YoY revenue analysis looks like this:

Figure 14: Final YoY Revenue Page

Analysis: YoY Margin


Looking only at the revenue can deceive about the company nancial health. The

margin analysis, comes to add information about the business. So, in a new page we

will make this analysis!

We will need our cost to calculate the margin. The cost comes from the chart

“fVendas” and depends on the unit cost of the product and how many units were sold,

thus being our measure:

Custo =

SUMX ( fVendas, fVendas[Custo Unitário] * fVendas[QtdItens] )

And our margin measurement is tied to our revenue and our cost:

Margem =

[Faturamento] – [Custo] 
/
(https://po
And to calculate the previous year’s margin, just use the SAMEPERIODLASTYEAR: avancado-
 Português
comparac
medias/)
Margem LY =(https://powerbiexperience.com/)

CALCULATE ( [Margem], SAMEPERIODLASTYEAR ( dCalendario[Data] ) )

With both, we can calculate the variation:

Margem YoY =

[Margem] – [Margem LY]

We will start to analyze with the table design. With it, we will understand by category

how much we improved or worsened in relation to the previous year (remember that

the lter of the year is for 2018):

Figure 15: Margin analysis chart


/
(https://po
Stage: avancado-
 Português
comparac
In "Visualizações" select "Tabela" → Set up the space according to th
medias/)
(https://powerbiexperience.com/)

We already see that we have worsened the margin, even having a bigger revenue

(Revenue 2018 = $ 10,214,809, 41/Revenue 2017 = $ 6,648,222,05/Increase of = 53,65

%).

Well, imagine you have presented this result to your manager, and he started to get

worried. And now what? How to help him understands this information!? Remember

the scatter splot? It is a great tool to kind of situation

The rst step is to create a scatter plot with the information of variation of margin and

revenue variation by category:

Figura 1e: Scatter plot chart

Stage:

In "Visualizações" select "Gráfico de dispersão" → Set up the space a

Well, with this chart you can better understand the analysis!? Di cult, right!? We still

have how to improve and a lot…. the second step is to divide this chart in 4 quadrants:

1 – Positive Margin and Positive Revenue; 


/
2 – Negative Margin and Positive Revenue;
(https://po
3 – Negative Margin and Negative Revenue; avancado-
 Português
comparac
4 – Positive Margin and Negative Revenue. medias/)
(https://powerbiexperience.com/)

To make this division in the chart, we use the help of “Analysis” …. is that magnifying

glass button next to the format roll:

Figure 17: Adding lines to create quadrants

Stages:

1. In "Análise" select "Linha Constante do Eixo X" → Valor = 0

2. In "Análise" select "Linha Constante do Eixo Y" → Valor = 0

Creating lines, that’s our chart:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 18: Scatter plot with quadrants

This way, we already have a much better idea of where we should analyze in more

detail. Imagine that we can create a lter that makes the segmentation of these

quadrants. It would help, right? Yes, and I say more… let’s do it. Let’s create a

segmentation chart with the limits:


/
Figure 19: Segmentation chart
(https://po
avancado-
 Português
comparac
medias/)
Stage: (https://powerbiexperience.com/)
In "Página Inicial" select "Inserir dados" → Fill chart as image

Important:

Whenever you create segmentation charts, enter in managing relationships to analyze

if Power BI didn’t automatically create relationships for this new chart.

Let’s delete a relationship that Power BI automatically made between this and the

other segmentation table:

Figure 20: Deleting relationship


/
(https://po
Stage: avancado-
 Português
comparac
In "Modelagem" select "Gerenciar relações" → "Excluir relação" betwee
medias/)
(https://powerbiexperience.com/)

Remember how we managed to use this kind of segmentation for invoicing!? We had

to put these limits within a measure for Power BI to apply context to each line. So,

here we will do something very similar:

Margem YoY por Categoria =

CALCULATE (

[Margem YoY],

FILTER (

VALUES ( dCliente[Categoria] ),

[Faturamento YoY] >= MIN ( SegmentoMC[LimInfFat] )

&& [Faturamento YoY] < MAX ( SegmentoMC[LimISupFat] )

&& [Margem YoY] >= MIN ( SegmentoMC[LimInfMC] )

&& [Margem YoY] < MAX ( SegmentoMC[LimSupMC] )

Important:

Limits are applied and associated only for “Category” of the client! If you want to

create this analysis for customer table information, you must change the VALUES part

of the measurement.

With this measurement, we change the elds of our scatter plot by adding the subtitle

with quadrant and changing the x-axis measurement:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 21: Updated scatter plot

Stage:

Add "Legenda" and update "Eixo X"

And we will also create 3 visuals to provide the user with information to analyze

customer categories and products with low margin and have a data segmentation per

quadrant:

Figure 22: Stacked bar chart


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 23: Waterfall Chart

Figure 24: Quadrant Filter

Stages:

1. In "Visualizações" select "Gráfico de barras empilhado" → Set up t

2. In "Visualizações" select "Gráfico de cascata" → Set up the space

3. In "Visualizações" select "Segmentação de dados" → Set up the spac

With the visuals ready, we have our YoY margin analysis page ready, which looks like

this:

/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 25: YoY Margin Page

Cross sell
Cross-sell analysis is well known for retail and distribution people. I don’t know if you

know that story of an American market that analyzed its sales and realized that on

Fridays the quantity of beer and diaper shopping on the same purchase was high. This

happened because normally the parents who were going to buy the diapers already

took the opportunity to take the weekend beer home. This is a very classic example of

Market Basket Analysis, and it helps users a lot to try to understand their sales.

The idea here is to quantify how many customers have bought a certain product A (e.g.

beer) and also bought product B (e.g. diaper).

The rst step is to create the measurement for counting customers:

Clientes =

DISTINCTCOUNT ( fVendas[cdCliente] )

And make this count by group in a table view:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 26: Products and quantity table

Good, here we have the information we need (product and quantity). However, we

need the duplicate product information! Think with me, you will be analyzing a product

on one side in a chart and this has to be related (so two charts) with another product in

another chart.

You can create this chart virtually, but here we will duplicate the chart “dProduto” in

Power Query:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 27: Duplicating the product chart

Stapes:

1. In "Página inicial" select "Transformar dados"

2. Right-click on the table dProduto → Click on "Duplicar" e rename

With the duplicate table, we can close and apply to return to the Power BI desktop.

Remember what I said back there about what can happen when we create new chart in

the project? Power BI can create relationships automatically! In this case, it created the

relationship between the original product chart and the copy. We will need this

relationship, however we will leave it inactive:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 27: Disabling the relationship between the charts

Stage:

In "Modelagem" select "Gerenciar relações" → Disable relationship

To calculate the customers who bought both from the group selected in the rst data

segmentation (Grupo – dProduto) and in the second data segmentation (Grupo 1 –

dProdAux1) we use the intersection between them. For this we will create a measure

using INTERSECT:

Clientes Cross =

VAR vClientes0 =

VALUES ( fVendas[cdCliente] )

VAR vClientes1 =

CALCULATETABLE (

VALUES ( fVendas[cdCliente] ),

ALL ( dProduto ),

USERELATIONSHIP ( dProdutoAux1[cdProduto], fVendas[cdProd

uto] )

)

VAR vInt =
/
INTERSECT ( vClientes0, vClientes1 )
(https://po
avancado-
RETURN  Português
comparac
COUNTROWS ( vInt ) medias/)
(https://powerbiexperience.com/)

We will apply two data segmentations on the page (Açucares to Grupo and Farinha de

Trigo to Grupo 1) and check the cross sell result for this analysis:

Figure 28: Two group segmentation visuals


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 29: Result chart with the applied lters

Stages:

1. Inm "Visualizações" select "Segmentação de dados" → Create 2 filte

2. In "Visualizações" select "Segmentação de dados" → Set up accordin

Having the measures of quantity of customers who bought the product and also the

cross sell. There is a way to evaluate the percentage relation between them with a

measure. This measure is called “Con ança” (nomenclature used in statistics).

Confiança =

DIVIDE ( [Clientes Cross], [Clientes] )

And with it we build our matrix visual:


/
Figure 30: Cross sell matrix (con ança)
(https://po
avancado-
 Português
comparac
medias/)
Stage: (https://powerbiexperience.com/)
In "Visualizações" select "Matriz" → Set up according to the image -

To leave a more intelligible visual to our user, we can build a heat map on the matrix:

Figure 31: Conditional formatting of the “Con ança” eld

Stage:

In "Valores" click on the cursor in the right of "Confiança" → Select

Figure 32: Matrix result with Heat Map


/
So, what do you think of the visual? Did you notice that when the line is equal to the
(https://po
column (“Açúcar” x “Açúcar”, “Óleo x Óleo”, etc…) the values are 
100% and that gives Português
a avancado-
comparac
“polluted” visual? We can change the measure of “Con ança” so that the return is medias/)
(https://powerbiexperience.com/)
empty in these cases, greatly improving the visual:

Confiança =

IF (

SELECTEDVALUE ( dProduto[Grupo] ) <> SELECTEDVALUE ( dProduto

Aux1[Grupo] ),

DIVIDE ( [Clientes Cross], [Clientes] )

Figure 33: Visual after changing the “Con ança” measure

It’s getting pretty, huh?

Well, now imagine that instead of analyzing 2 products you have 3. This was a question

of one of our students in the Telegram group when I was setting up Live #27, and that

makes more complicated to calculate.

To do this, we will create another copy chart of dProdutos in Power Query:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 34: New copy of dProduto (dProdAux2)

Disable the relationship between dProduto and this copy:

Figure 35: Desabling relationship

And now, we need to add in our measure a new intersection which is the result of the

rst intersection with this second calculated column:



/
Clientes Cross =
(https://po
avancado-
VAR vClientes0 =  Português
comparac
VALUES (https://powerbiexperience.com/)
( fVendas[cdCliente] ) medias/)

VAR vClientes1 =

CALCULATETABLE (

VALUES ( fVendas[cdCliente] ),

ALL ( dProduto ),

USERELATIONSHIP ( dProdutoAux1[cdProduto], fVendas[cdProd

uto] )

VAR vClientes2 =

CALCULATETABLE (

VALUES ( fVendas[cdCliente] ),

ALL ( dProduto ),

USERELATIONSHIP ( dProdutoAux2[cdProduto], fVendas[cdProd

uto] )

VAR vInt01 =

INTERSECT ( vClientes0, vClientes1 )

VAR vInt12 =

INTERSECT ( vInt01, vClientes2 )

RETURN

COUNTROWS ( vInt12 )

That’s it! With this we can apply 3 lters on the page (Grupo – dProduto, Grupo 1 –

dProdAux1 and Grupo 2 – dProdAux2) that our visuals will work for this context:


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 36: Page data segmentation

Figure 37: Result of applied lter

Stages:

1. Create another segmentation on the page → Grupo2 - dProdAux2


/
Average per categor y (https://po
avancado-
 Português
comparac
This is an interesting analysis to evaluate how one or some categories behave
medias/)
(https://powerbiexperience.com/)
compared to the total.

As it is a comparison, we have to create two measures. The rst one will be the

average revenue per client, considering lters applied if the user wants to evaluate

some speci c group. And the second, the average revenue of all clients (disregarding

any lter applied to visuals) that we use ALL to disregard applied contexts.

Fat Médio por Cliente =

AVERAGEX ( VALUES ( dCliente[cdCliente] ), [Faturamento] )

Fat Médio por Todos Cliente =

CALCULATE ( [Fat Médio por Cliente], ALL ( dCliente ) )

And starting from them, we will create 3 visuals:

Data segmentation: for the user to choose which category to analyze

Chart: with the group and the two measures to show the values

Column and Row Graph: to analyze how the variation in the result of the selected

category with the total mean was


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 38: Data segmentation

Figure 39: Comparison Chart



/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 40: Column and row chart

And the result with the applied lter (bakery, in the example) looks like this:

Figure 41: Page result with applied lter

Stages:

1. In "Visualizações" select "Segmentação de dados" → Set up the fiel

2. In "Visualizações" select "Tabela" → Set up the fields according t

3. In "Visualizações" select "Gráfico de colunas e linha" → Set up th

Analysis per Week 


/
People often ask me and ask questions about week time analysis. This is not the kind
(https://po
of analysis that is so complicated if you use a counter for the weeks avancado-
in your Português
comparac
dCalendario. Working with this counter makes it much easier to do those analyses medias/)
(https://powerbiexperience.com/)
when it turns a year (for example, from week 52 to week 1).

We will build this counter in 2 steps. First we will create the number of the week in our

dCalendario and then by mathematical logic we can create the counter:

Figure 42: Creating a new column

Semana do Ano =

WEEKNUM ( dCalendario[Data] )

Contador Semana =

( dCalendario[Ano] – 2017 ) * 53 + dCalendario[Semana do Ano]


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 43: Result of dCalendario with the two columns

Stage:

1. In "Dados" select the chart "dCalendario" → In "Ferramentas de col

2. Use the DAX formula for "Semana do Ano"

3. Repeat step 1

4. Use the DAX formula for "Contador Semana"

With this column to help, we were able to create our comparative measures for the

“Faturamento da Semana Passada” (LW Revenue) and the last “Faturamento de 4

semanas” (Average 4W Revenue):

Faturamento LW =

CALCULATE (

[Faturamento],

FILTER (

ALL ( dCalendario ),

dCalendario[Contador Semana]

= MAX ( dCalendario[Contador Semana] ) – 1 


/
)
(https://po
avancado-
)  Português
comparac
medias/)
(https://powerbiexperience.com/)
Fat Médio 4W =

VAR vSemanaContexto =

MAX ( dCalendario[Contador Semana] )

RETURN

CALCULATE (

[Faturamento]

/ CALCULATE ( DISTINCTCOUNT ( dCalendario[Contador Se

mana] ), fVendas ),

FILTER (

ALL ( dCalendario ),

dCalendario[Contador Semana] <= vSemanaContexto

&& dCalendario[Contador Semana] > vSemanaContexto

– 4


/
(https://po
avancado-
 Português
comparac
medias/)
(https://powerbiexperience.com/)

Figure 44: Revenue Analysis, LW Revenue and 4W Revenue

Stages:

1. Create measures of "Faturamento LW" and "Fat Médio 4W"

2. In "Visualizações" select "Matriz" → Set up fields according to th

Well, guys, that was our Live #27 content!! A lot of what I did here were questions and

suggestions from the people in the social networks. So, I hope it helped you to

understand these analyses that are at a more advanced level of DAX. If you have any

questions or suggestions for the next Lives topics, you already know, you can leave

them in the comments.

Cheers,

Leonardo.

/
(https://po
avancado-
 Português
comparac
Share this post:
(https://powerbiexperience.com/)
medias/)

   

 (https://powerbiexperience.com/en/using (https://powerbiexperience.com/en/how-

0 Comments Sort by Oldest

Add a comment...

Facebook Comments Plugin


/

You might also like