I have the following query :
SELECT d.department
,COUNT(*)
FROM fact_table AS f
LEFT JOIN
(SELECT DISTINCT sk_dept, department FROM dim_department ) AS d ON d.sk_dept=f.fk_dept
WHERE f.employee_status <> 2
GROUP BY d.department
This is the output of the query :
Department Count
1 250
2 300
The department dimension is like below :
DepartmentSK DepartmentId SubDepartment
1 1 23
2 1 67
3 1 120
4 2 44
The Dept has sub department my measure is showing me duplicates :
Employee Count By Dept =
CALCULATE (
DISTINCTCOUNT( fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
How can we include the LEFT JOIN subquery containing distinct in the DAX measure?
The output I get with the DAX formula :
Department Count
1 500
2 600
The count is duplicated because the deptid is existing many times since each department has many sub departments.
Try to SUMX with the DISTINCT to get the unique values of the department :
Employee Count By Dept =
SUMX (
DISTINCT(VALUES(dim_department[department])),
CALCULATE (
DISTINCTCOUNT(fact_table[employeeID]),
DIM_Status[employee_status] <> 2
)
)
)
Related
I have a text file that looks like this:
;MPV_F4(isHold, taps, state)
MPV_F5(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
MPV_F6(isHold, taps, state)
;MPV_F7(isHold, taps, state)
;MPV_F8(isHold, taps, state)
;MPV_F9(isHold, taps, state)
;MPV_F11(isHold, taps, state)
MPV_N2(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
;MPV_N3(isHold, taps, state)
;MPV_N4(isHold, taps, state)
;MPV_N5(isHold, taps, state)
which essentially consists of a repeating pattern of:
FunctionName(isHold, taps, state)
{
<Function Body>
}
I am trying to break it down into arrays that consists of the function name and body. I cant use the string MPV in my regex as there are other similar texts files whose function names does not contain MPV.
My exepected output is:
$MyVar [0] :
MPV_F5(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
$MyVar [1] :
MPV_N2(isHold, taps, state)
{
if (taps == 1)
{
if (isHold == 0)
{
;[HV] T1 | cycle mute | This is long LONG
Sendinput, {U+0398} ;Θ ; ;[rr] [cycle mute ]
}
else
{
if (state)
{
while GetKeyState("f5", "p"){
Sendinput, {U+0399} ;Ι ; ;[rr] [add volume 10 ]
sleep, 55
}
}
; else
; {
; }
}
}
}
At first I tried to use Get-Content's -Delimeter parameter:
$mytextfile = "c:\temp\mytextfile.txt"
Get-content $mytextfile -Delimiter '.*[^;]\(isHold, taps, state\)'
It keeps returning the entire content as a single object, After a few more variations I resorted to just using Get-Content -Raw and then -Split operator:
$MyVar = $mytextfile -Split (?m).*[^;]\(isHold, taps, state\)(?s).*\}
I continue to get unexpected results, most commonly the entire content being returned instead of arrays.
I am using RegEx101*, and options are closesly aligned to what powershell expects. I have tried many variations with no desired results.
Here is a link my RegEx101 page.
What could I be doing wrong here?
Any help would be truelly wellcome.
Try the following:
$MyVar =
[regex]::Matches(
(Get-Content -Raw $mytextfile),
'(?sm)\w+\(isHold, taps, state\)\s*\{(?:.(?!\w+\(\w))+\}'
).Value
Note that this approach is computation-intensive and relies on detecting the end of a function not by properly detecting nested { / } pairs, but by assuming that the presence of any subsequent <funcname>(<wordcharacter> substring (e.g. 'MPV_F6(i') implies that the most recent } ended the function body.
See this regex101.com page.
I created a multi-timbral instrument application based on multiple AVAudioUnitSampler instances (one per Midi channel), wrapped in a custom AVSampler class.
I want to expose it also as an AUv3. I followed some articles and samples and put the view controller and other classes in a Framework target, created an AudioUnit extension target (with a dummy/empty class file as I've no implementation to provide).
In the extension's Info.plist (NSExtensionAttributes) I added AudioComponentBundle (points to the AUFramework) and AudioComponents item with factoryFunction (points to $(PRODUCT_MODULE_NAME).MultiSamplerViewController), aumu type. Also added NSExtensionPrincipalClass pointing to AUFramework.MultiSamplerViewController.
In the shared MultiSamplerViewController I implemented
(AUAudioUnit *)createAudioUnitWithComponentDescription:(AudioComponentDescription)desc error:(NSError **)error {
return [[[multiSampler engine] outputNode] AUAudioUnit];
}
It also contains an - (id)initWithCoder:(NSCoder*)decoder method, that instantiates the wrapping MultiSampler and starts an enclosed MidiManager.
The host application target runs fine, however the AU extension plugin isn't listed in GarageBand (even after runnig the host application once). The target platform is iPad.
I added code to load the appex plugin bundle, however it doesn't seem enough to register the plugin. Also I cannot use the AUAudioUnit registerSubclass as I've no concrete AU implementation class (only my wrapper class).
I'm in the same configuration as an application built on AudioKit framework (that originally wrapped AVAudioUnitSampler - and now uses a custom implementation). I looked into AudioKit code and found they implemented AudioUnit protocols methods in their wrapper class (https://github.com/AudioKit/AUv3-Example-App/blob/master/Example%20Plugin%20App%20AU/Audio%20Unit/ExampleApp_AudioUnit.swift). However I don't know what to do in AUAudioUnit methods implementation (setOutputBusArrays, allocateRenderResources, internalRenderBlock, etc.)
EDIT :
I may have to implement AUaudioUnit callbacks.
To pass mainMixerNode buffers to AUaudioUnit render callback I could store (in memory, so would grow over time... not ideal) these through installTapOnBus, and then access these from render callback.
AVSampler : AUAudioUnit
createAudioEngine
...
[mixerNode installTapOnBus:0
bufferSize:4096
format:[[AVAudioFormat alloc]initWithStreamDescription:&audioFormat]
block:^(AVAudioPCMBuffer * _Nonnull buffer, AVAudioTime * _Nonnull when) {
[self.timeToBuffer addObject:buffer forKey:when];
}];
(AUInternalRenderBlock)internalRenderBlock {
return ^AUAudioUnitStatus(AudioUnitRenderActionFlags *actionFlags,
const AudioTimeStamp *timestamp,
AVAudioFrameCount frameCount,
NSInteger outputBusNumber,
AudioBufferList *outputBufferListPtr,
const AURenderEvent *realtimeEventListHead,
AURenderPullInputBlock pullInputBlock ) {
int outputNumBuffers = outputBufferListPtr->mNumberBuffers;
float *ptrLeft = (float*)outputBufferListPtr->mBuffers[0].mData;
float *ptrRight = NULL;
if (outputNumBuffers == 2) {
ptrRight = (float*)outputBufferListPtr->mBuffers[1].mData;
}
AVAudioPCMBuffer *mixerNodeBuffer = [self.timeToBuffer objectForKey:timestamp];
mixerNodeBuffer.audioBufferList.pointee.mBuffers
int n = frameCount;
if(mixerNodeBuffer.frameLength == frameCount)
for (int i=0;i<n;i++) {
ptrLeft[i] = mixerNodeBuffer.floatChannelData[0].pointee[n];
ptrRight[i] = mixerNodeBuffer.floatChannelData[1].pointee[n];
}
}
}
I have a very large dataset with multiple columns to sum and categories, but here is an example of what i am trying to do:
I want to sum up the "dollars" column to the total Account Number level based on which line with account number has the highest number in the "people" column. So there is just 1 line for every account number, and the State column will have whichever state has the higher people in it.
Account Number State Dollars People
1 MA 200 5
1 NY 100 2
2 CT 150 3
3 OH 100 3
4 VA 300 7
4 FL 100 3
and it will look like this after the code:
Account Number State Dollars People
1 MA 300 7
2 CT 150 3
3 OH 100 3
4 VA 400 10
I think this may be a simple fix but please help!
Thanks in advance!!
proc sql;
create table T2 as
select 'Account Number'n, State, sum(Dollars) as Dollars, sum(People) as People, People as People_Order
from T1
group by 'Account Number'n
order by People_Order desc
;quit;
/* keep the first row within previously performed Order By: */
proc sort data=T2 (drop=People_Order) nodupkey; by 'Account Number'n;run;
Sorry I'm lost I really appreciate if you can help me calculate the follwoing
So I've a table two fy data LY(Last Year) FY2020 and (This Year) or FY2021,
I would like to compare this year we spent on Agency vs Avg Spent on LY
Agency spend vs last year average; expressed as % of total people costs spend in month
The table output is like
2020 2021
F_Month AgencyPaid2020 msrAgencyPayPrv AgencyPay msrAgencyPayPrv
1 217922 18161 37930 18161
2 296460 24705 56155 24705
3 298863 24905 0 24905
. xxxx xxxxx 0 xxxx
.
12 110166 9181 0
--- --------- ------------ ------------- --------------
Total 169955 141630 18225 141630
I'm expecting 141630 should show in all rows for above table(Col2) but when I drag the measure into table its calculating differently
The measure I've calculated is
> msrAgencyPayPrvYearAvg =
> CALCULATE(SUM(Data[IM_Actual_Positive]),Data[EBITDA]="2
> Pay",Data[PayCat_1]="Agency",Data[int_fyear]=2020)/12'''
Thanks for you help
The 4th column should not show 2021 is there a way I can hide as its coming because in the 'Visualization' under column I've put 'int_fyear' column
and vales I've (Agency Pay and msrAvgAgencyPay) , sorry I 've lost the plot
Kind regards,
Farhan
I've found the answer I should use the following function
msrAgencyPaySheet =
CALCULATE(Sum(Sheet1[Actual]),filter(ALLSELECTED(Sheet1), Sheet1[FY]=2020))/12
Im new in soap request, my client send me sample request format but he told me that I was'nt able to pass the parameter correctly. I dont know if my codes are the problem, I paste the sample request and my code
Thanks
here is the sample request:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:card="http://placeholder/CARD">
<soapenv:Header/>
<soapenv:Body>
<card:CardPrinting>
<!--Optional:-->
<WebRequestCommon>
<!--Optional:-->
<company></company>
<password></password>
<userName>CARDPRINTING</userName>
</WebRequestCommon>
<!--Optional:-->
<PSSLAICARDPRINTINGType>
<!--Zero or more repetitions:-->
<enquiryInputCollection>
<!--Optional:-->
<columnName>CUSTOMER.CODE</columnName>
<!--Optional:-->
<criteriaValue>100115</criteriaValue>
<!--Optional:-->
<operand>EQ</operand>
</enquiryInputCollection>
</PSSLAICARDPRINTINGType>
</card:CardPrinting>
</soapenv:Body>
</soapenv:Envelope>
Here is my code is
$client = new SoapClient('http://placeholder/CARD/services?wsdl');
$params = array(
'WebRequestCommon'=>array(
'company'=>'',
'password'=>'123456',
'userName'=>'TAMIZH4'
),
'PSSLAICARDPRINTINGType'=>array(
'enquiryInputCollection'=>array(
'columnName'=>'CUSTOMER.CODE',
'criteriaValue'=>'100115',
'operand'=>'EQ'
)
)
);
$students = $client->CardPrinting($params);