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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Create new column based on specific row value grouped by ID in DirectQuery

I have a table similar to to what is shown below in DirectQuery. I want to create a new column with NewDate grouped by ID. Do note Response column is of string type but new column would be of Date type. Thanks in advance!

 

Date|ID|Question|Response
10/31/2022|001|Role|Manager
10/31/2022|001|Rate|20
10/31/2022|001|NewDate|06/15/2022
11/1/2022|002|Role|Server
11/1/2022|002|Rate|10
11/1/2022|002|NewDate|07/15/2022

 

Date|ID|Question|Response|NewDate
10/31/2022|001|Role|Manager|6/15/2022
10/31/2022|001|Rate|20|6/15/2022
10/31/2022|001|NewDate|06/15/2022|6/15/2022
11/1/2022|002|Role|Server|7/15/2022
11/1/2022|002|Rate|10|7/15/2022
11/1/2022|002|NewDate|07/15/2022|7/15/2022
13 REPLIES 13
Anonymous
Not applicable

Hi @Anonymous ,

I have created a simple sample, please refer to it to see if it helps you.

Create 2 measures.

_1 = IF(MAX('Sheet1$'[Question])="Newdate",MAX('Sheet1$'[Response]),BLANK())

Measure= MAXX(FILTER(ALL('Sheet1$'),'Sheet1$'[ID]=SELECTEDVALUE('Sheet1$'[ID])),[_1])

vpollymsft_0-1667365775990.png

 

 

If it still does not help, please provide your pbix file without privacy information for us testing.

 

Best Regards

Community Support Team _ Polly

 

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

Anonymous
Not applicable

@Anonymous 

Thanks for replying. I just got blank values returned since my table is a lot more complex than the example I provided. It is using direct query which wouldnt be useful if I share the pbix file?

tamerj1
Super User
Super User

Hi @Anonymous 

Please try

NewDate =
DATEVALUE (
    MAXX (
        FILTER (
            CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
            NOT ISERROR ( DATEVALUE ( 'Table'[Response] ) )
        ),
        'Table'[Response]
    )
)
Anonymous
Not applicable

Hi @tamerj1 . Thanks for your response.

 

I do get the error 'Function MAXX is not allowed as part of calculated column dax expressions on direct query models'. Maybe using SELECTCOLUMNS function?

@Anonymous 

Yes indeed. I hate direct query. Please try

NewDate =
DATEVALUE (
    SELECTCOLUMNS (
        FILTER (
            CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[ID] ) ),
            NOT ISERROR ( DATEVALUE ( 'Table'[Response] ) )
        ),
        "@NewDate", 'Table'[Response]
    )
)
Anonymous
Not applicable

@tamerj1 

Same Error: Function 'SELECTCOLUMNS' is not allowed as part of calculated column DAX expressions on DirectQuery models.

 

Then created a seperate table with duplicate values and got 'A table of multiple values was supplied where a single value was expected.'

@Anonymous 

That means you have multiple dates per ID try to include [Date] with the ALLEXCEPT 

NewDate =
DATEVALUE (
    MAXX (
        FILTER (
            CALCULATETABLE ( 'Table', ALLEXCEPT ( 'Table', 'Table'[ID], 'Table'[Date] ) ),
            NOT ISERROR ( DATEVALUE ( 'Table'[Response] ) )
        ),
        'Table'[Response]
    )
)
Anonymous
Not applicable

@tamerj1 

 

hmm I am simply getting [Date] again.

@Anonymous 
Not possible. Please paste a screenshot of the dax code

Anonymous
Not applicable

@tamerj1 

I just replaced Date with SubmittedDate, ID with SubmissionID, and Response with ResponseText. I find it very weird too how it grabs the submitteddate 

 

DATEVALUE (
    MAXX (
        FILTER (
            CALCULATETABLE ( 'CI_FormAll Solar', ALLEXCEPT ( 'CI_FormAll Solar', 'CI_FormAll Solar'[SubmissionID] ,'CI_FormAll Solar'[SubmittedDate] ) ),
            NOT ISERROR ( DATEVALUE ( 'CI_FormAll Solar'[ResponseText] ) )
        ),
        'CI_FormAll Solar'[ResponseText]
    )
)
Nandez_0-1667418041127.png

 

@Anonymous 
Just a trial, please use the same code without NOT and the outer DATEVALUE

=
MAXX (
    FILTER (
        CALCULATETABLE (
            'CI_FormAll Solar',
            ALLEXCEPT (
                'CI_FormAll Solar',
                'CI_FormAll Solar'[SubmissionID],
                'CI_FormAll Solar'[SubmittedDate]
            )
        ),
        NOT ISERROR ( DATEVALUE ( 'CI_FormAll Solar'[ResponseText] ) )
    ),
    'CI_FormAll Solar'[ResponseText]
)

 

Anonymous
Not applicable

@tamerj1 

 

Same result, well now it is not datetime type but still submitteddate date-type

@Anonymous 

Should be something related to direct query. Or perhaps I'm missing something. I should seek help from the best in the field @Greg_Deckler  @amitchandak 

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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