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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
ninimoke
Helper I
Helper I

Dax Calculation Across Two Tables

I have a DAX calculation that perfectly works when using single table, now I ned to select columns across two tables bu I am getting error. Attaches is a screenshot. I would love if I can get help on this. Thanks.Capture.PNG

1 ACCEPTED SOLUTION
v-xinruzhu-msft
Community Support
Community Support

Hi @ninimoke  ,

 

If you are using a measure , you cannot directly reference a column in a table in a measure, you need to use a function to apply to a table column.

If you are using calculated columns, if there is a correspondence between the two tables (such as one-to-many), you can use the related() function to refer to a column in another table.

e.grelated(Alertsvulns[Created Date])

 

 Best Regards,

Yolo Zhu

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

View solution in original post

4 REPLIES 4
v-xinruzhu-msft
Community Support
Community Support

Hi @ninimoke  ,

 

If you are using a measure , you cannot directly reference a column in a table in a measure, you need to use a function to apply to a table column.

If you are using calculated columns, if there is a correspondence between the two tables (such as one-to-many), you can use the related() function to refer to a column in another table.

e.grelated(Alertsvulns[Created Date])

 

 Best Regards,

Yolo Zhu

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

tamerj1
Super User
Super User

Hi @ninimoke 

please try

OOSLA =
VAR _Today =
TODAY ()
VAR _Date =
SELECTEDVALUE ( Alertsvulns[Created Date] )
VAR _Severity =
SELECTEDVALUE ( Machinevulns[severity] )
VAR _DiffDays = _Today - _Date
RETURN
SWITCH (
TRUE (),
_Severity = "Medium"
&& _DiffDays >= 90, _DiffDays - 90,
_Severity = "Low"
&& _DiffDays >= 120, _DiffDays - 120,
_DiffDays >= 30, DiffDays - 30,
_Severity = "Critical"
&& _DiffDays >= 30, _DiffDays - 30
)

@tamerj1 Thanks for the respons. This throws no error but all the calculaton turns out to be 0.

@ninimoke 
Please try

OOSLA =
VAR _Severity =
    SELECTEDVALUE ( Machinevulns[severity] )
VAR _DiffDays =
    SUMX ( Alertsvulns, DATEDIFF ( Alertsvulns[Created Date], TODAY (), DAY ) )
RETURN
    SWITCH (
        TRUE (),
        _Severity = "Medium"
            && _DiffDays >= 90, _DiffDays - 90,
        _Severity = "Low"
            && _DiffDays >= 120, _DiffDays - 120,
        _DiffDays >= 30, DiffDays - 30,
        _Severity = "Critical"
            && _DiffDays >= 30, _DiffDays - 30
    )

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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

Top Solution Authors