avatarShashanka Shekhar

Free AI web copilot to create summaries, insights and extended knowledge, download it at here

2769

Abstract

e_data[sales_per_order]), Calender[Date])</i></b></p><figure id="4c97"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*6jS6sbDDDlLpdr7wO6LTfQ.png"><figcaption>DAX for YTD Sales</figcaption></figure><p id="abb2"><b><i>PYTD Sales = CALCULATE(SUM(ecommerce_data[sales_per_order]), SAMEPERIODLASTYEAR(Calender[Date]))</i></b></p><figure id="ab04"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*AM7_Jzu_nLOGV6Kiawsvog.png"><figcaption>DAX for PYTD Sales</figcaption></figure><p id="cbcd">Now I have already written an article about what <i>YTD</i> and<i> PYTD</i> are and how their DAX work so please refer to this <a href="https://medium.com/@shashanka.shekhar02/top-3-most-important-growth-metrics-in-powerbi-ytd-pytd-and-yoy-in-under-3-minutes-f1f75fa30d7c"><b><i>link</i></b></a><i> </i>for knowing that, trust me it is very easy.</p><p id="f8ca"><b><i>YoY Sales = ([YTD Sales] — [PYTD Sales])/[PYTD Sales]</i></b></p><figure id="d607"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*PkCRget4Du0OnATVCUEwww.png"><figcaption>DAX for YoY Sales</figcaption></figure><p id="8ad6">Now just take a <i>card</i> visual from<i> Visualization pane</i> and place <i>YoY Sales</i> to it. Also select <i>YoY Sales</i> from <i>Data pane </i>then a <i>measure tools</i> option will come above from which click on <b><i>%</i></b> icon and give 2 value to decimal digits.</p><figure id="959c"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*snhBKi0nBeScL5ToUMgPpg.png"><figcaption>Make sure YoY Sales is selected</figcaption></figure><h2 id="b08c">3.DAX for Indicator Creation:</h2><p id="6235"><b><i>Sales Indicator = var positive_icon = UNICHAR(9650)</i></b></p><p id="7fd0"><b><i>var negative_icon = UNICHAR(9660)</i></b></p><p id="e364"><b><i>var result = IF([YoY Sales]>0, positive_icon, negative_icon)</i></b></p><p id="d5af"><b><i>return result</i></b></p><figure id="5cc1"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*iqojk5DazMOg6vKZeTn-zA.png"><figcaption>DAX for Indicator Creation</figcaption></figure><p id="982a">here we are creating two<i> variables positive icon </i>and<i> negative icon</i> with positive icon getting a value of <b>UNICHAR(9650)</b> where <b>9650</b> is unichar value of ▲ and for negative icon we are giving <b>UNICHAR(9660)</b> where <b>9660</b> is unichar value of ▼.</p><p id="af4d">now we will create a third <i>variable result </i>where we run a IF condition i.e. if <b>YoY Sales > 0(positive)</b> then <i>result</i> will take ▲ and if <b>YoY Sales <0(negative)</b> then <i>result </i>will<i> </i>take<i> </i>▼ and finally we return the result.</p><h2 id="c32d">4.DAX for Background Colour:</h2><p id="aee9">Now we want the background to take <

Options

i>Green</i> or <i>Red</i> colour depending on the <b>YoY Sales</b> value for which we will use a DAX:</p><p id="4b33"><b><i>Sales Colour = IF([YoY Sales]>0,”Green”,”Red”)</i></b></p><figure id="5807"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*NqG1YBpgpg5sOAtF3iAlrg.png"><figcaption>DAX for Sales Colour</figcaption></figure><p id="eea5">Its simple, <b>IF YoY Sales>0</b> then <b>Sales Colour = Green </b>and if <b>IF YoY Sales<0 </b>then<b> Sales Colour = Red</b>.</p><p id="5ed0">Now just go to <b>Insert </b>and add a rectangle from <b>shapes. </b>Then create the rectangle select it and in <b>Format</b> pane go to <b>Shape, Style</b> and <b>Fill</b> and click <b><i>fx</i></b>. Now in <b>Format Style</b> choose <b>Rules </b>and in field select Sales Colour then type <b>Green</b> and <b>Red </b>in the same way as you wrote in the <b>IF</b> condition of <b><i>Sales Colour. </i></b>Then choose the colours from More colors.. if needed and press OK.</p><figure id="ba4e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*6MJt3xyfzqUqu5LZkrwcOg.png"><figcaption>Make sure to type Green and Red as in IF condition</figcaption></figure><figure id="cafe"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*LVdABDr7vZrcVxxwkcAKag.png"><figcaption>Use More colors.. if needed</figcaption></figure><p id="420a">Finally put the <i>YoY Sales</i> and <i>Sales Indicator</i> in cards if not done already and put it over the rectangle created and your KPI is created.</p><figure id="ebcb"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*-5EMiIsFVsqg13Aq3tWzXQ.png"><figcaption>Created KPI in this article</figcaption></figure><p id="ee86"><i>To create a Concatenated KPI refer to this <a href="https://medium.com/@shashanka.shekhar02/3-easy-steps-to-make-a-concatenated-kpi-in-power-bi-dd5d14f60fb8"><b>link</b></a>.</i></p><p id="7255"><i>To read more stories like this you can follow me with this <a href="https://medium.com/@shashanka.shekhar02"><b>link</b></a>.</i></p><h1 id="3eae">References:</h1><ol><li><a href="https://www.investopedia.com/terms/k/kpi.asp">https://www.investopedia.com/terms/k/kpi.asp</a></li><li><a href="https://www.forbes.com/advisor/business/what-is-a-kpi-definition-examples/">https://www.forbes.com/advisor/business/what-is-a-kpi-definition-examples/</a></li><li><a href="https://en.wikipedia.org/wiki/Performance_indicator">https://en.wikipedia.org/wiki/Performance_indicator</a></li></ol><p id="a817" type="7">Don’t forget to subscribe to</p><p id="02af" type="7">👉 Power BI Publication</p><p id="a1d7" type="7">👉 Power BI Newsletter</p><p id="b0d9" type="7">and join our Power BI community</p><p id="bf84" type="7">👉 Power BI Masterclass</p></article></body>

4 easy steps to create a KPI with an indicator in Power BI

Power BI is a platform that allows you to connect to various data sources, transform and model your data, and create interactive dashboards and reports. Power BI can help you gain insights from your data and communicate them effectively.

What is a KPI?

A KPI, or a key performance indicator, is a measurable target that shows how well an individual or a business is performing in terms of meeting their goals. KPIs can be financial, such as net profit or revenue, or nonfinancial, such as customer satisfaction or retention. KPIs help organizations track their progress, identify their strengths and weaknesses, and make informed decisions to improve their outcomes.

A snapshot of an Ecommerce Dashboard in Power BI

Building the KPI

We will be making this KPI:

YoY Sales KPI with an indicator

So to calculate YoY Sales first we need YTD Sales and PYTD Sales which require the need for a calendar table because there is a requirement of creating a calendar table whenever we are dealing with dates in Power BI.

1.DAX for calendar table creation:

Calender = CALENDAR(MIN(ecommerce_data[order_date]), MAX(ecommerce_data[order_date]))

DAX for calendar table creation

where the arguments are the start and end dates in the main table which here is ecommerce_data and the MIN() and MAX() functions give us the min and max dates in ecommerce_data table which are nothing but our start and end dates.

Then this calendar table needs to be connected to the main table in data modelling section of Power BI. Just drag Date column in calendar table to the respective date column in main table. Refer this article for connecting the tables, it is very easy to do.

2.DAX for YoY Sales:

As mentioned earlier YoY Sales requires YTD Sales and PYTD Sales so we will calculate them first.

YTD Sales = TOTALYTD(SUM(ecommerce_data[sales_per_order]), Calender[Date])

DAX for YTD Sales

PYTD Sales = CALCULATE(SUM(ecommerce_data[sales_per_order]), SAMEPERIODLASTYEAR(Calender[Date]))

DAX for PYTD Sales

Now I have already written an article about what YTD and PYTD are and how their DAX work so please refer to this link for knowing that, trust me it is very easy.

YoY Sales = ([YTD Sales] — [PYTD Sales])/[PYTD Sales]

DAX for YoY Sales

Now just take a card visual from Visualization pane and place YoY Sales to it. Also select YoY Sales from Data pane then a measure tools option will come above from which click on % icon and give 2 value to decimal digits.

Make sure YoY Sales is selected

3.DAX for Indicator Creation:

Sales Indicator = var positive_icon = UNICHAR(9650)

var negative_icon = UNICHAR(9660)

var result = IF([YoY Sales]>0, positive_icon, negative_icon)

return result

DAX for Indicator Creation

here we are creating two variables positive icon and negative icon with positive icon getting a value of UNICHAR(9650) where 9650 is unichar value of ▲ and for negative icon we are giving UNICHAR(9660) where 9660 is unichar value of ▼.

now we will create a third variable result where we run a IF condition i.e. if YoY Sales > 0(positive) then result will take ▲ and if YoY Sales <0(negative) then result will take ▼ and finally we return the result.

4.DAX for Background Colour:

Now we want the background to take Green or Red colour depending on the YoY Sales value for which we will use a DAX:

Sales Colour = IF([YoY Sales]>0,”Green”,”Red”)

DAX for Sales Colour

Its simple, IF YoY Sales>0 then Sales Colour = Green and if IF YoY Sales<0 then Sales Colour = Red.

Now just go to Insert and add a rectangle from shapes. Then create the rectangle select it and in Format pane go to Shape, Style and Fill and click fx. Now in Format Style choose Rules and in field select Sales Colour then type Green and Red in the same way as you wrote in the IF condition of Sales Colour. Then choose the colours from More colors.. if needed and press OK.

Make sure to type Green and Red as in IF condition
Use More colors.. if needed

Finally put the YoY Sales and Sales Indicator in cards if not done already and put it over the rectangle created and your KPI is created.

Created KPI in this article

To create a Concatenated KPI refer to this link.

To read more stories like this you can follow me with this link.

References:

  1. https://www.investopedia.com/terms/k/kpi.asp
  2. https://www.forbes.com/advisor/business/what-is-a-kpi-definition-examples/
  3. https://en.wikipedia.org/wiki/Performance_indicator

Don’t forget to subscribe to

👉 Power BI Publication

👉 Power BI Newsletter

and join our Power BI community

👉 Power BI Masterclass

Power Bi
Dax
Kpi
Data Visualization
Power Bi Tips And Tricks
Recommended from ReadMedium