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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ilcaa72
Helper IV
Helper IV

return multiple Vars in Dax

im new to Dax.  here is my Dax formula. 

 

I keep messing up and pressing alt enter, then enter incorrectly which deletes my columns... what is the proper syntax to return all 3 variables at the same time as 3 seperate columns?  thanks

 

dates = 

var basetable =
    CALENDAR(DATE(2016,1,1),today())

var addyears = 
     ADDCOLUMNS(basetable,"year",YEAR([Date]))

var addmonths =
    ADDCOLUMNS(
    basetable,
        "monthid", FORMAT( [Date], "yyyymm"), 
        "month", FORMAT( [Date], "mmm yy")
   )
return ???  (all 4 columns)

 

 

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Try this.  It's a little advanced, and came from www.sqlbi.com  Check out this article for the full explanation

 

Calendar = 
VAR BaseCalendar =
    CALENDAR ( DATE ( 2016, 1, 1 ), DATE ( YEAR( TODAY() ), 12, 31 ) )
RETURN
    GENERATE (
        BaseCalendar,
        VAR BaseDate = [Date]
        VAR YearDate = YEAR ( BaseDate )
        VAR MonthNumber = MONTH ( BaseDate )
        VAR MonthName = FORMAT ( BaseDate, "mmmm" )
        VAR YearMonthName = FORMAT ( BaseDate, "mmm yy" )
        VAR YearMonthNumber = YearDate * 12 + MonthNumber – 1
        RETURN ROW (
            "Day", BaseDate,
            "Year", YearDate,
            "Month Number", MonthNumber,
            "Month", MonthName,
            "Year Month Number", YearMonthNumber,
            "Year Month", YearMonthName
        )
    )

View solution in original post

3 REPLIES 3
v-jiascu-msft
Employee
Employee

Hi @ilcaa72,

 

Is your code here just a demo? Just see from the code, we don't need to use this complex code. @Anonymous's solution is great. Besides, the three variables will return three table type values rather than three columns. If you post the desired result, maybe we can find out a better solution.

 

 

Best Regards,

Dale

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

Hi 

Please help me I'm trying to return multplie values into one table column. My code is 

 

OTPMeasure = var PercDiffEarlyOTP = CALCULATE(DIVIDE([Early OTP Selected Day],[Total OTP Selected Day],1) * 100 - (DIVIDE([Early OTP Past 30 Days],[Total OTP Past 30 Days],1)) *100)


var PercDiffLateOTP = CALCULATE(DIVIDE([Late OTP Selected Day],[Total OTP Selected Day],1) * 100 - (DIVIDE([Late OTP Past 30 Days],[Total OTP Past 30 Days],1)) *100)


var PercDiffOnTimeOTP = CALCULATE(DIVIDE([On Time OTP Selected Day],[Total OTP Selected Day],1) * 100 - (DIVIDE([On Time OTP Past 30 Days],[Total OTP Past 30 Days],1)) *100) 

return PercDiffEarlyOTP ,PercDiffLateOTP ,PercDiffOnTimeOTP  

Anonymous
Not applicable

Try this.  It's a little advanced, and came from www.sqlbi.com  Check out this article for the full explanation

 

Calendar = 
VAR BaseCalendar =
    CALENDAR ( DATE ( 2016, 1, 1 ), DATE ( YEAR( TODAY() ), 12, 31 ) )
RETURN
    GENERATE (
        BaseCalendar,
        VAR BaseDate = [Date]
        VAR YearDate = YEAR ( BaseDate )
        VAR MonthNumber = MONTH ( BaseDate )
        VAR MonthName = FORMAT ( BaseDate, "mmmm" )
        VAR YearMonthName = FORMAT ( BaseDate, "mmm yy" )
        VAR YearMonthNumber = YearDate * 12 + MonthNumber – 1
        RETURN ROW (
            "Day", BaseDate,
            "Year", YearDate,
            "Month Number", MonthNumber,
            "Month", MonthName,
            "Year Month Number", YearMonthNumber,
            "Year Month", YearMonthName
        )
    )

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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