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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
pavithrarajan
Frequent Visitor

How to convert this sql query to DAX

How to convert this sql query to DAX in a measure

Select value from KPI A
where period in (
    select B.period from 
Time B  join   period C 
on B.period=c.Period
where b.quater >= c.quater-1 and  b.quater <= c.quater-5

5 REPLIES 5
Kedar_Pande
Super User
Super User

@pavithrarajan 

DAX measure:

Selected Value = 
VAR CurrentQuarter = MAX('Period'[Quarter])
VAR FilteredPeriods =
FILTER(
ALL('Time'),
'Time'[Quarter] >= CurrentQuarter - 5 &&
'Time'[Quarter] <= CurrentQuarter - 1
)
RETURN
CALCULATE(
MAX('KPI A'[Value]),
'KPI A'[Period] IN DISTINCT(SELECTCOLUMNS(FilteredPeriods, "Period", 'Time'[Period]))
)

💌 If this helped, a Kudos 👍 or Solution mark would be great! 🎉
Cheers,
Kedar
Connect on LinkedIn

sample 

pavithrarajan_0-1734707081779.png

 

Anonymous
Not applicable

Hi, @pavithrarajan 

 

May I ask if your problem is solved? If not resolved, can you provide sample data and your expected output? This will better describe your problem. How to provide sample data in the Power BI Forum - Microsoft Fabric Community

 

Best Regards,

Community Support Team _Charlotte

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

Kaviraj11
Super User
Super User

Try this -

Measure = 
CALCULATE(
    SUM('KPI A'[value]),
    FILTER(
        'KPI A',
        'KPI A'[period] IN 
        SELECTCOLUMNS(
            FILTER(
                CROSSJOIN('Time', 'period'),
                'Time'[period] = 'period'[Period] &&
                'Time'[quarter] >= 'period'[quarter] - 1 &&
                'Time'[quarter] <= 'period'[quarter] - 5
            ),
            "period", 'Time'[period]
        )
    )
)



Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.