top of page
Power BI | Excel | Python | SQL
Search


Pivot and Unpivot in DAX
Today, let's take a look at how to do Pivot and Unpivot in DAX. Ideally you would do this in SQL or Power Query but it never hurts to see how you could do same with DAX, infact you might get a better understanding of a very special DAX function. For Pivoting we are working with StudentsScore data. To PIVOT in SQL we could write following 2 queries that return different results depending on the requirement SELECT * FROM StudentScores AS S PIVOT ( SUM(Score) FOR Subject IN (Eng

Antriksh Sharma
5 days ago3 min read


Get Rows from Previous Partition into Current Partition
Today, I am going to show you how to bring/join the rows of previous partition with the current partition in DAX, with the metrics for the previous rows in the current time frame. From the above image you can see there are 2 Customers in 2021 that are brought forward into 2022 with their Sales in 2021 and Sales in 2022. First order of business is to get TOPN Customers in each year and for that we can use TOPN paired with GENERATE or with WINDOW VAR N = 2 VAR TopCustomersEvery

Antriksh Sharma
Apr 253 min read


Fill Up and Down in DAX v2
In an earlier blog post I showed how to implement Fill Up and Fill Down in DAX that relied heavily on using Calculated Columns. However now that I have more experience with WINDOW functions I can show you a solution that does all of that with just measures. But first I will introduce a simpler dataset that makes it easier to consume. The table contains only 3 columns. These 3 columns together do not make up unique combination, the row (2025-02-01, null, null) is present twice

Antriksh Sharma
Apr 103 min read


Using NONVISUAL in DAX
DAX has an interesting function named NONVISUAL, which marks a Filter in SUMMARIZECOLUMNS to impact only the grouping columns and not affect the measures. We have model where there are Years in the Dates[Year] from 2020 - 2026 but the Sales only occured for 2021 - 2025, so when a user writes a DAX Query like the following one it returns 5. DEFINE MEASURE Sales[#Years in Dates] = COUNTROWS ( ALLSELECTED ( Dates[Year] ) ) EVALUATE SUMMARIZECOLUMNS ( ProductCategory[C

Antriksh Sharma
Jan 193 min read


User Defined FUNCTION in a DAX Query
In this blog let's take a look at how to use DAX's UDF in a DAX Query that mixes TABLE, COLUMN, MEASURE, and FUNCTION keywords. We start with a UDF that returns Dates[Year] by the position that we pass, the focus is primarily on First and Last values when there are Years in Dates table that do not have a row in Sales table. Following UDF code returns First and Last Years: DEFINE FUNCTION FxGetValueByPosition = ( N: INT64 VAL, OrderByCol: ANYREF EXPR, SortOrder: ANYREF EXPR )

Antriksh Sharma
Jan 163 min read


Generate Ranked Pairs in DAX
Let's say you want Top 2 Colors of each Brand, how would you do that? Here are different ways of computing that. Using INDEX & UNION DEFINE VAR Temp = ADDCOLUMNS ( ALL ( Products[Brand], Products[Color] ), "@Sales", [Sales Amount] ) VAR Uno = INDEX ( 1, Temp, ORDERBY ( [@Sales], DESC ), PARTITIONBY ( Products[Brand] ) ) VAR Dos = INDEX ( 2, Temp, ORDERBY ( [@Sales], DESC ), PARTITIONBY ( Products[Brand] ) ) EVALUATE UNION ( Uno, D

Antriksh Sharma
Jan 131 min read


Show values for last N months in DAX
Today, I am going to explain how to show values in a Power BI visual but only for the last month or last N months.

Antriksh Sharma
Jan 37 min read


Detecting Matrix Levels in DAX with ISINSCOPE
In a Matrix like above there are many places where you can show/hide values, when we think of it there are mainly 5 areas, Rows, Columns, Rows Total, Column Totals, and Grand Totals, but you can have many more levels by some boolean tricks. So how do we control where exactly to show a value or which area to hide them from? by using ISINSCOPE. This function not only tells whether you're grouping by a certain column at certain level but you can use it as boolean mask or an inte

Antriksh Sharma
Dec 23, 20254 min read


Implementing Fill Up and Fill Down in DAX
In this blog let's take a look at how you can Fill blank cells with values before or after them also know as Fill Up or Fill Down in various tools.

Antriksh Sharma
Apr 11, 20253 min read


Fixing Lineage issue when JOIN-ing tables in DAX
DAX has 2 functions that allow you to JOIN tables and columns i.e. NATURALINNERJOIN & NATURALLEFTOUTERJOIN, although there is no...

Antriksh Sharma
Nov 21, 20242 min read


Why DAX is returning 100%
In this blog let's take a look at why your DAX calculations are returning 100% instead of a fraction of the grand total. In DAX you can...

Antriksh Sharma
Oct 19, 20243 min read


Understanding how Time Intelligence functions are evaluated in Row Context
I have been thinking about this for a while, a series of blogs where I try to explain how a particular piece of DAX code works. For this...

Antriksh Sharma
May 16, 20248 min read


Using DETAILROWS with WINDOW functions in DAX
DAX doesn't have the concept of global variables so reusing a piece of code by referencing it somewhere else isn't possible, luckily the...

Antriksh Sharma
Apr 13, 20244 min read


Applying a Filter on Dimension vs Fact in DAX
While working with DAX, a common mistake that anyone makes (that I also made) is to think that applying a filter on a column of a...

Antriksh Sharma
May 10, 20234 min read


ALL Functions vs Security in DAX
One thing that we are used to is ALL functions ignore filters and return either a unique value or complete table when used as a table...

Antriksh Sharma
Apr 28, 20231 min read


Complex behaviour of slicers in Power BI
Recently I faced a situation where a simple measure such as COUNTROWS was returning a blank, yeah what's up with that? COUNTROWS...

Antriksh Sharma
Apr 29, 20223 min read


Full Outer Join in DAX in Power BI and SSAS Tabular
DAX language of Power BI and SSAS Tabular doesn't have a function for Full Outer Join so in this blog we are going to see a work around...

Antriksh Sharma
Mar 28, 20225 min read


Storing a column as String or Integer in Analysis Services
Recently someone asked a question that whether they should store a column in a Tabular model in String or Integer format and in this short blog I just want to help you decide it by yourself. In Power Query I have create 2 tables with different data types Let's load these tables in the data model and open DAX Studio and view the vertipaq Analyzer metrics. We can see that both column have a Dictionary encoding: The size of the dictionary varies however, the overall size mention

Antriksh Sharma
Dec 20, 20212 min read


Dependency of a function on Row Context in DAX
Have you ever writen a piece of DAX Code that looks like this: and ended up confused how is it able to calculate how many years, days,...

Antriksh Sharma
Nov 18, 20214 min read


SUM vs SUMX in DAX
SUM and SUMX are both aggregation functions in DAX. While SUM allows you to aggregate only one Physical column of a table, SUMX is more...

Antriksh Sharma
Sep 1, 20214 min read


Previous Year calculation in case of missing years in DAX.
One of the most common time intelligence calculations that I see in each report is that of Previous Year, this calculation is pretty easy...

Antriksh Sharma
Aug 3, 20212 min read


How to create Running Total in Power BI: The Basics
In this tutorial lets see how easy it is to create a running total in DAX either in SSAS, Power Pivot or Power BI. Running total is a...

Antriksh Sharma
Jul 12, 20214 min read


Show measures in Power BI based on slicer selection
One of the very common requirement of Power BI users is that of showing only those measures in a visual which are selected in a slicer....

Antriksh Sharma
Jun 30, 20211 min read


Create Calculated Table in Power BI with Tabular Editor
Out of the box TE doesn't allows you to create Calculated Table in Power BI, but if you want you can easily do that. To be able to create...

Antriksh Sharma
Jun 8, 20211 min read
bottom of page