Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
fahim_ash123
New Member

Power BI DAX Formula for a measured value

Hi,

 

I am quite new to Power Bi

 

The Following Query in SQL will give me the most popular item based on the highest OrderQuantity.

 

How would I go about producing the same thing as a new measure in Power BI

 

Select top(1)
Description as [Most Popular Item]
from
(
SELECT
[ItemsId]
,Description
,Sum(OrderQuantity) as [Quantity Sold]

FROM [Data_Analysis].[dbo].[dimFactTable] as F

left join [Data_Analysis].[dbo].[dimItems] as I

on
f.ItemsId=i.Items_Id

group by [ItemsId] ,Description

) as tmp

order by [Quantity Sold] desc

4 REPLIES 4
fahim_ash123
New Member

Hi,

 

I am quite new to Power Bi

 

The Following Query in SQL will give me the most popular item based on the highest OrderQuantity.

 

How would I go about producing the same thing as a new measure in Power BI

 

Select top(1)
Description as [Most Popular Item]
from
(
SELECT
[ItemsId]
,Description
,Sum(OrderQuantity) as [Quantity Sold]

FROM [Data_Analysis].[dbo].[dimFactTable] as F

left join [Data_Analysis].[dbo].[dimItems] as I

on
f.ItemsId=i.Items_Id

group by [ItemsId] ,Description

) as tmp

order by [Quantity Sold] desc

Look for TOPN function.

ibarrau
Super User
Super User

Hi there. First you should check you SQL because it has sintax errors. One thing you need to know about dax is that joining is not a regular operation. Why? beacause you have relationships on your tabular model that will execute joins depending on how you show the data in power bi visualization.

 

Then I ask, what do you need? a table, measure or column?

 

IF you have related the FactTable and Items by id, then try this measure to get the first description. This is only to replicate your query, I don't  think this is the best way to know the first description with most Quantity sold. You can get this on a visualization with description as categorical and sum orderquantity order by desc having advanced filter with topn in 1.

 

Most Popular Item =
MAXX (
    SUMMARIZE (
        dimFactTable,
        dimFactTable[itemsId],
        dimFactTable[Description],
        "Quantity Sold"SUM ( dimFactTable[OrderQuantity] )
    ORDER BY [Quantity Sold] DESC,
    Description
)

 

I have my doubts about that Order By. Let me know if it works. Otherwise we can try ADDCOLUMNS to get the sumarization.

Regards, hope this works


If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Happy to help!

LaDataWeb Blog

Hi,

Thanks for the reply

 

What is wrong with my SQL Syntax? 

 

It seems to execute prefectley in SSMS 

 

Your DAX Formula Doesn't seems to be working with the order by caluse

 

 

 

 

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.