MDX for Last 2 Members in Fact, not from Dim

I'm trying to write an mdx that will give me the last 2 Products sold in my Fact table, but instead of that, I always get the latest 2 Products in my Dim table sold.
I've googled it, but cannot get the right mdx, so I can retrieve the last records in my fact. So far I have:
WITH MEMBER [last] as
FILTER([DIM_PRODUCT].[PRODUCT_ID].[PRODUCT_ID].MEMBERS,[Measures].[Row Count]).item(
FILTER([DIM_PRODUCT].[PRODUCT_ID].[PRODUCT_ID].MEMBERS,[Measures].[Row Count]).count-1).name
MEMBER [previous] as
FILTER([DIM_PRODUCT].[PRODUCT_ID].[PRODUCT_ID].MEMBERS,[Measures].[Row Count]).item(
FILTER([DIM_PRODUCT].[PRODUCT_ID].[PRODUCT_ID].MEMBERS,[Measures].[Row Count]).count-2).name
SELECT {[last],[previous]} on COLUMNS
FROM [Cube]
where [DIM_WAREHOUSE].[WAREHOUSE_ID].&[2]
Any help will be highly appreciated. Thanks!

Hi XanderAS,
According to your description, you want to query the last two products, right? In this case, we can use
Tail function which returns a subset from the end of a set to achieve you requirement. Here is a sample MDX query on Adventure works for your reference.
with MEMBER [Measures].[LastMember Name] as [Date].[Calendar].CURRENTMEMBER.UNIQUE_NAME
select {[Measures].[Internet Sales Amount],[Measures].[LastMember Name]} on 0
,{TAIL([Date].[Calendar].[Date].members,2)} on 1
from [Adventure Works]
Regards,
Charlie Liao
TechNet Community Support

Similar Messages

  • Not able text one contact for last 5 days. Its not his phone. I'm receiving his texts OK

    My friend has stopped receiving my texts about 4 days ago. I get his OK. Its not his phone as he sens & receives texts from his other contacts

    Actually, since you are receiving his texts just fine, I would suggest you also have him contact his carrier to see why his inbound texts from you are not getting to him.  It could be a problem with his carrier not accepting traffic from your carrier.

  • For last 24 hours we have not had a mobile phone signal. NR12 8UN

    Can you tell me what the problem is please? Post code NR12 8UN

    Can you tell me what the problem is please? Post code NR12 8UN

  • Where is the easy answer for getting all music, purchased or not, from the nano to my itunes library again?

    I can't believe that Apple doesn't have a way for Nano owners to put their music on their Nano
    back on their pc's in the itunes library after it is erased by their 14 year old son!!  I have a music
    collection on there, purchased and from CD's, and I want it back on my pc too to make playlists.
    Have music on my Nano - want it also on my computer(itunes) again.  Didn't know it was a one way street.
    Is there a easy and free way? 

    http://support.apple.com/kb/HT1329

  • Notes from Outlook 2010 are missing

    Hi,
    After one of the last software updates of Q10, Notes from Outlook that previously appeared in "remember" screen (without any relation with Outlook entries, but at least there they were) are missing.
    Would be good to hear if is there any way to get it back.
    Best regards,
    Miguel Lezama

    Might be worth running SCANOST on this one (possibly the first time in history that I've recommended that utility).
    See if this helps: http://www.officeforlawyers.com/outlook/tsol.htm#scanpst (the instructions are basically the same for SCANOST)
    -B-
    http://www.officeforlawyers.com
    Author: The Lawyer's Guide to Microsoft Outlook

  • Constructing Calculated Measures in MDX for different measures using same columns in a fact table

    Hello,
    i have a fact table with 2 columns corresponding to dimensions Dim1, Dim2. In the same table i have 4 other columns Value_Type(int), INT_VALUE(int), FLOAT_VALUE(float), TEXT_VALUE(string). There are a number of measures which are identified by Value_Type and
    depending on their nature could be written in one of the 3 columns (INT_VALUE(int), FLOAT_VALUE(float), TEXT_VALUE(string)) Let's say Measure1 with Measure_Type=1 is age, 2 is account balance and 3 is Name for clarity. There could be other measure types that
    use these 3 same columns for data. So the sample fact table looks like this
    Dim1 Dim2 Measure_Type INT_VALUE FLOAT_VALUE TEXT_VALUE
    10 10 1 25
    10 10 2 2000,34
    10 10 3 John
    10 20 1 28
    10 20 2 3490,23
    10 20 3 Frank
    My task is to write an MDX query for each Dim1, Dim2 combination which returns all 3 measures in the same row. The idea is to construct a calculated member for each Measure that returns value from the right field. For example for Measure1 we take INT_VALUE
    with measure_type=1. The problem is i don't know how to construct MDX query for these calculated members. Can you please help me?
    So my final goal is to write an MDX query that returns all measures in one row for each set of Dim1, Dim2
    SELECT [Measure1], [Measure2], [Measure3] ON COLUMNS,
    NON EMPTY [Dim1].[Dim1].[Dim1].Members*[Dim2].[Dim2].[Dim2].Members ON ROWS
    FROM [Cube]
    Dim1 Dim2 Measure1 Measure2 Measure3
    10 10 25 2000,34 John
    10 20 28 3490,23 Frank

    Hi Kosmipt,
    I would combine the "INT_VALUE", "FLOAT_VALUE" and "TEXT_VALUE" columns into one with STRING data type for the fact table. And there should be one dimension to store the Measure_Type informations. Then in cube, you can write MDX scope for every one of
    "Measure_Type" dimension members. For example,
    scope(
                [Measures].[M]
        [DimMType].[MType].&[1]= CINT([Measures].[M]);                                                                                                                             
    end scope;
    Once the cube is built by the above way, you can write MDX like something like the following to achieve your purpose.
    WITH member [Measures].[Measure1] AS ([DimMType].[MType].&[1],[Measures].[M])
             member [Measures].[Measure2] AS ([DimMType].[MType].&[2],[Measures].[M])
             member [Measures].[Measure3] AS ([DimMType].[MType].&[3],[Measures].[M])
    thanks,
    Jerry

  • I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    I bought new Macbook Pro 13" around two months before .My Apple ID is working on all other things except app store . It is buffering for a lot of time and lastly coming on screen " can not connect to app store " Please help me

    Have you tried repairing disk permissions : iTunes download error -45054

  • My Time Capsule has stopped backing up.  I have an Apple Time Capsule which backs up by wireless. For the last 3 days it has not backed up. I get this message: "The backup was not performed because an error occurred while copying files to the backup disk.

    My Time Capsule has stopped backing up.
    I have an Apple Time Capsule which backs up by wireless. For the last 3 days it has not backed up. I get this message:
    "The backup was not performed because an error occurred while copying files to the backup disk."
    I have gone into Mac Help and followed this down to stage 4:
    under shared it lists my time capsule and my husband's iMac - both use the time machine but we have switched his off temporarily.  Clicking on my Time capsule I get "Connected" and "Sharepoint" - I didn't have to enter connect or password
    I don't understand stage 5: how and where do I select the disk or volume that contains Time Machine backups ?  How do I know which it is? My disk utility lists 160.04 TOSHIBA MK... with sub-heading Macintosh HD.  It also lists (with a "CD" icon) HL-DT-ST DVDRW GS22N
    Under stage 6, how and where do I Locate your backup ? I try dragging my Time capsule from Finder to the Disk Utility side panel but it won't go.  What is my computer's name?
    Please someone help!  I'm completely stumped.
    Thanks,
    Maggie
    Mac Help says:
    If you back up to a Time Capsule or network disk:
    Open the Time Machine pane of System Preferences, and slide the switch to Off.
    Open Time Machine preferences
    Open Disk Utility, which is in the Utilities folder in the Applications folder. 
    Open Disk Utility
    Make sure the Time Capsule or network disk is turned on and available. 
    Open a Finder window, select your Time Capsule or network disk in the Shared section of the sidebar, and click Connect. If necessary, enter your user name and password. 
    On the Time Capsule or network disk, select the disk or volume that contains Time Machine backups. Depending on how your Time Capsule is set up, there may be one or more disks or volumes. 
    Locate your backup, and drag it to the Disk Utility sidebar.You can identify your backup by looking for your computer’s name in the backup’s filename.

    Hello,
    Thanks to the great Pondini...
    http://pondini.org/TM/C3.html

  • Please read my question carefully, this is, I think, a question for the experts. It's not the usual name change question.   When I setup my new MacBook Pro, something slipped by me and my computer was named First-Lasts-MacBook-Pro (using my real first and

    Please read my question carefully, this is, I think, a question for the experts. It's not the usual name change question.
    When I setup my new MacBook Pro, something slipped by me and my computer was named First-Lasts-MacBook-Pro (using my real first and last name).
    I changed the computer name in Preferences/Sharing to a new name and Preferences/Accounts to just be Mike. I can right click on my account name, choose advanced, and see that everything looks right.
    However, If I do a scan of my network with my iPhone using the free version of IP Scanner, it lists my computer as First-Lasts-MacBook-Pro! And it lists the user as First-Last.
    So even though another Mac just sees my new computer name, and my home folder is Mike, somewhere in the system the original setup with my full name is still stored. And it's available on a network scan. So my full name might show up at a coffee shop.
    Can I fully change the name without doing a complete re-install of Lion and all my apps?

    One thought... you said the iPhone displayed your computer's old name? I think that you must have used the iPhone with this computer before you changed the name. So no one else's iPhone should display your full name unless that iPhone had previously connected to your Mac. For example, I did this exact same change, and I use the Keynote Remote app to connect with my MacBook Pro. It would no longer link with my MacBook Pro under the old name, and I found that I had to unlink and then create a new link under the new name. So the answer to your question is, there is nothing you need to do on the Mac, but rather the phone, and no other phone will display your full name.

  • HT204053 Is it possible to have two (or more) different icloud mail accounts (not alias) under the same apple id? If not what is you best advice for all family members to have their own e-mail and still share the purchases under the same apple id. Thanks

    Is it possible to have two (or more) different icloud mail accounts (not alias) under the same apple id? If not what is you best advice for all family members to have their own e-mail and still share the purchases under the same apple id. Thanks

    mannyace wrote:
    Thanks for the response.
    So I basically won't run into any trouble? I
    There should be no issues. Its designed to work like that.  You don't change Apple IDs just because you get a new device.
    mannyace wrote:
    Thanks for the response.
    Is there any chance that the phones can fall out of sync?
    Unlikely. But nothing is impossible.   Though I don;t see how that would happen. As long as both are signed into the Same Apple ID / iCloud Account they will be N'Sync. (Bad Joke)
    mannyace wrote:
    Thanks for the response.
    If I get a message or buy an app or take a photo on the iPhone 5, how do I get those things onto the iPhone 6?
    If you buy an App, you have 2 ways to get it to the iPhone6: If Automatic Downloads is enabled in Settings->iTunes & App Store, it will automatically download to the iPhone 6 when you buy it on the 5 and vice versa if you buy it on the 6, it will download to the 5.
    Alternatively, you can simply go to the App Store App->Updates->Purchased and look for the App there and download it. Purchased Apps will not require payment again. i.e They'll be free to download to the iPhone 6 once purchased.
    SMS Messages will sync over using Continuity as long as they are on the same Wifi network. Otherwise, restoring the iPhone 5 backup to the iPhone 6 will transfer all messages received up until the backup was made onto the iPhone 6.
    Images, can be transferred either through Photo Stream
    My Photo Stream FAQ - Apple Support
    Or any Cloud service you want such as Dropbox, or One Drive.
    mannyace wrote:
    Also, something i forgot to ask initially: Should I update the iPhone 5 to iOS 8 first or does that not matter?
    If you want the Continuity features as explained above you need to update the iPhone 5 to iOS 8. Otherwise its not all that important.

  • HT1476 My iPhone 4S will charge on a laptop but not from a wall plug. I have tried different boxes and different USB cords from the wall but none work. These boxes and USB cords work for other family members with iPhones. I'm stumped :/

    My iPhone 4S will charge on a laptop but not from a wall plug. I have tried different boxes and different USB cords from the wall but none work. These boxes and USB cords work for other family members with iPhones and a USB cord that works from the laptop won't work from 3 or 4 different wall boxes that work for others. I'm stumped :/

    Update: It seems as though the phone will charge if I plug it in and then turn it off.  It will not charge while the phone is on.  Also iTunes will not recognize it, so I can't sync or anything.  I read somewhere that it could be a fuse somewhere?? Or maybe the dock connector. Where is the best place to get this repaired?

  • Urgent - Not able to Print back page for Last Page in SAP Script.

    Hello All,
    I need to Print back page in SAP Script, I am able to do it by setting print mode as D, but now the problem is, it does not print back page for last page.
    For eg. if there are 3 pages it prints back page for first two. If there is only one page then it does not print back page.
    Please Help.
    Thanks.

    hi,
    Yes, we can print logo as water mark in scripts
    Just do as like this....
    Upload your logo via SE78.
    - Select 'Import' button from application toolbar of SE78, and perform upload.
    and write this code in scripts
    BITMAP 'COMPANY_LOGO' OBJECT GRAPHICS ID BMAP TYPE BCOL 
    regards
    Sankar

  • I am using Iphone 3gs. Last week I updated my itunes to latest version, although I couldnt not update my iphone OS since the download fails saying error 9006. For last 2 days all my Iphone applications fail to open except the default ones. Any solutions?

    I am using Iphone 3gs. Last week I updated my itunes to latest version, although I couldnt not update my iphone OS since the download fails saying error 9006. For last 2 days all my Iphone applications fail to open except the default ones. Any solutions?

    Download a free app and try again, you can delete the free app afterward.

  • Hi hope somebody can help? i have acrobat 6 pro, worked well for last two years but then just stopped working. Have reinstalled but still will not open, ronning windows 7. Help please!!

    Hi hope somebody can help? i have acrobat 6 pro, worked well for last two years but then just stopped working. Have reinstalled but still will not open, ronning windows 7. Help please!!  Janice

    Hey janicem42177174,
    Adobe no longer supports the installation and use of Acrobat 6 as it is a very old version which is not compatible with Windows 7.
    I would suggest you to please use the latest version of Acrobat i.e. 11.0.10 which is fully compatible with your OS with its enhanced features and functions.
    You might download a free 30-day trial version of Acrobat from here:
    Download Adobe Acrobat free trial | Acrobat XI Professional
    Let me know how it goes
    Regards,
    Anubha

  • I heard that there was a problem with Apple being vulnerable to Hackers. Has anyone seen an update for this issue? My IPad received the update last night but I have not seen anything for Safari.

    I heard that there was a problem with Apple being vulnerable to Hackers. Has anyone seen an update for this issue? My IPad received the update last night but I have not seen anything for Safari.

    Mac OS X 10.9.2 was released today for this issue and others. Earlier versions are not affected.
    See this Apple article - http://support.apple.com/kb/HT6114
    You can use the Mac app store to do the update or download it directly from here - http://support.apple.com/kb/DL1725
    Best of luck.

Maybe you are looking for