Search code examples
ssasmdx

custom count measure runs forever MDX


So this question goes off the one here

I've been trying to do a similar count measure and I did the suggested solution but it's still running.... and it's been more than 30 minutes with no results, while without that it runs in under a minute. So am I missing something? Any guidance would help. Here is my query:

WITH 
    MEMBER [Measures].[IteractionCount] AS 
    NONEMPTY
    (
        FILTER
        (
            ([DimInteraction].[InteractionId].[ALL].Children,
            [Measures].[Impression Count]),
            [DimInteraction].[Interaction State].&[Enabled]
        )
    ).count

SELECT 
(
    {[Measures].[IteractionCount],
    [Measures].[Impression Count]}
)
ON COLUMNS,
(   

    ([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
     [DimCampaign].[Campaign Name].[Campaign Name].MEMBERS, 
     [DimCampaign].[Owner].[Owner].MEMBERS)
    ,[DimDate].[date].[date].MEMBERS
)
ON ROWS
FROM 
(
    SELECT 
    (
       {[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
    )
    ON COLUMNS 
    FROM [Model]
)
WHERE
(
        {[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL}, 
        [DimCampaign].[Campaign State].&[Active], 
        {[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
        //[DimInteraction].[Interaction State].&[Enabled]
)     

I don't know if FILTER is affecting it in any way but I tried it with and without and it still runs forever. I do need it specifically filtered to [DimInteraction].[Interaction State].&[Enabled]. I have also tried to instead filter to that option in the WHERE clause but no luck

Any suggestions to optimize this would be greatly appreciated! thanks!

UPDATE: I end up using this query to load data into a python dataframe. Here is my code for that. I used this script for connecting and loading the data. I had to make some edits to it though to use windows authentication.

ssas_api._load_assemblies() #this uses Windows Authentication
conn = ssas_api.set_conn_string(server='server name',db_name='db name')

df = ssas_api.get_DAX(connection_string=conn, dax_string=query))

The dax_string parameter is what accepts the dax or mdx query to pull from the cube.


Solution

  • Please try this optimization:

    
    WITH 
        MEMBER [Measures].[IteractionCount] AS 
        SUM
        (
            [DimInteraction].[InteractionId].[InteractionId].Members
             * [DimInteraction].[Interaction State].&[Enabled],
             IIF(
               IsEmpty([Measures].[Impression Count]),
               Null,
               1
             )
        )
    
    SELECT 
    (
        {[Measures].[IteractionCount],
        [Measures].[Impression Count]}
    )
    ON COLUMNS,
    (   
    
        ([DimCampaign].[CampaignId].[CampaignId].MEMBERS,
         [DimCampaign].[Campaign Name].[Campaign Name].MEMBERS, 
         [DimCampaign].[Owner].[Owner].MEMBERS)
        ,[DimDate].[date].[date].MEMBERS
    )
    PROPERTIES MEMBER_CAPTION
    ON ROWS
    FROM 
    (
        SELECT 
        (
           {[DimDate].[date].&[2020-05-06T00:00:00] : [DimDate].[date].&[2020-05-27T00:00:00]}
        )
        ON COLUMNS 
        FROM [Model]
    )
    WHERE
    (
            {[DimCampaign].[EndDate].&[2020-05-27T00:00:00]:NULL}, 
            [DimCampaign].[Campaign State].&[Active], 
            {[DimInteraction].[End Date].&[2020-05-27T00:00:00]:NULL}//,
            //[DimInteraction].[Interaction State].&[Enabled]
    )     
    CELL PROPERTIES VALUE
    
    

    If that doesn’t perform well the please describe the number of rows returned by your query when you comment out IteractionCount (sic) from the columns axis. And please describe how many unique InteractionId values you have.