Forum Discussion

Saxon10's avatar
Saxon10
Icon for Post Prodigy rankPost Prodigy
3 years ago

Index Direct Query

The source of data came from SQL server and I am not able to change the data or modify any new columns in SQL query.

How can I create a Index in direct query method. 

I can't use the power query options in direct query method and its not supporting use it. 

(From Index 0, From Index 1 and Customs)

Is there any measure formula able to create a Index in direct query method?

Could you please assist me. 

 

9 Replies

  • Hi Saxon10 ,

     

    In Direct query you cannot add any additional columns to your model, not sure how you have your setup but if you don't have any other ID field or detail field that allows you to have the distinction between the elements you can't have this directly.

     

    If you can edit the SQL you can has lbendlin  told edit in Power Query in order to add that column, however if you can't edit the Direct Query one optionmaybve it's to create an table using the generate series. Adding this table will create an composite model that has a direct query and import table in this case you can do the following:

    • Generate table with the count of rows of the ID you need to count:
    ID Table = 
    GENERATESERIES (
        1,
        MAXX (
            SUMMARIZE (
                'FACT',
                'FACT'[Type],
                "TOTALROWS", COUNTROWS ( 'FACT' )
            ),
            [TOTALROWS]
        ),
        1
    )
    • Create a Measure:
    Ranking =
    IF (
        SELECTEDVALUE ( 'ID Table'[Value] )
            <= COUNTROWS (
                FILTER ( ALLSELECTED ( 'FACT' ), 'FACT'[Type] = MAX ( 'FACT'[Type] ) )
            ),
        SELECTEDVALUE ( 'ID Table'[Value] )
    )
    • Create a table with the ID, the column from the Raking table and the Ranking metric

    This creates a duplication of the number of columns but you can then hide one of those columns.

     

    •  

     

    • lbendlin's avatar
      lbendlin
      Icon for Super User rankSuper User
      In Direct query you cannot add any additional columns to your model

      Well...  you can if you add a local model and the column is computed within the row.

      • MFelix's avatar
        MFelix
        Icon for Super User rankSuper User

        You are correct, what I meant was that keeping the model has direct query you cannot make those type of changes. Sorry for the error. 

    • Saxon10's avatar
      Saxon10
      Icon for Post Prodigy rankPost Prodigy

      Thanks for your reply and sorry for the late response. Some reason I haven't received the email notification so I missed the new message.

      Thanks for finding the solution to get the unique count 

      I will test your solution and update the feedback to you. 

    • Saxon10's avatar
      Saxon10
      Icon for Post Prodigy rankPost Prodigy

      MFelix,

      could you able to share the sample out file because I am receving error message. 

  • What are you trying to achieve with that index? Can you add the index in the SQL source?