If Modulus Is Not Equal To Zero - mfc

This code only works if the remainder is equal to zero:
CString temp;
int quarter = Emp_Max / 4;
int fstQrtr = quarter;
int scdQrtr = fstQrtr + quarter;
int trdQrtr = scdQrtr + quarter;
int fthQrtr = trdQrtr + quarter ;
int mod = Emp_Max % 4;
for(int i = 0 ; i < Emp_Max; i++){
EmpInfo[i].EmpLineName1 = "Emp_No";
EmpInfo[i].EmpLineName2 = "Emp_No";
EmpInfo[i].EmpLineName3 = "Emp_No";
EmpInfo[i].EmpLineName4 = "Emp_No";
if( i != Emp_Max )
{
temp.Format("EmpNo %d", i+1);
EmpName[i] = temp;
if (Emp_Max <= 4)
{
EmpInfo[i].EmpLineName1 = EmpName[i];
}
else
{
if (mod == 0)
{
if (i < fstQrtr)
{
EmpInfo[i].EmpLineName1 = EmpName[i];
}
else if (i < scdQrtr)
{
EmpInfo[i - fstQrtr].EmpLineName2 = EmpName[i];
}
else if (i < trdQrtr)
{
EmpInfo[i - scdQrtr].EmpLineName3 = EmpName[i];
}
else if (i < fthQrtr)
{
EmpInfo[i - trdQrtr].EmpLineName4 = EmpName[i];
}
}
}
}
}
If, for example, I declared Emp_Max = 16 or, in other words, if mod = 0, I get this output:
|==========|==========|==========|==========|
| Emp_No | Emp_No | Emp_No | Emp_No |
|==========|==========|==========|==========|
| EmpNo 01 | EmpNo 05 | EmpNo 09 | EmpNo 13 |
|==========|==========|==========|==========|
| EmpNo 02 | EmpNo 06 | EmpNo 10 | EmpNo 14 |
|==========|==========|==========|==========|
| EmpNo 03 | EmpNo 07 | EmpNo 11 | EmpNo 15 |
|==========|==========|==========|==========|
| EmpNo 04 | EmpNo 08 | EmpNo 12 | EmpNo 16 |
|==========|==========|==========|==========|
But if, for example, Emp_Max = 18 or in other words, if mod !=0, I still get the same output above instead of this:
|==========|==========|==========|==========|
| Emp_No | Emp_No | Emp_No | Emp_No |
|==========|==========|==========|==========|
| EmpNo 01 | EmpNo 06 | EmpNo 11 | EmpNo 15 |
|==========|==========|==========|==========|
| EmpNo 02 | EmpNo 07 | EmpNo 12 | EmpNo 16 |
|==========|==========|==========|==========|
| EmpNo 03 | EmpNo 08 | EmpNo 13 | EmpNo 17 |
|==========|==========|==========|==========|
| EmpNo 04 | EmpNo 09 | EmpNo 14 | EmpNo 18 |
|==========|==========|==========|==========|
| EmpNo 05 | EmpNo 10 | | |
|==========|==========|==========|==========|
What should I add or change to the code to get the target output? TIA.

int quarter = ceil(Emp_Max / 4.0)

Related

Why do some pins don't work with wiringPi?

I'm trying to write a simple program which uses the GPIO pins of the Raspberry Pi 3B.
When I run the following program, only the LED on pin 17 flashes.
Pin 27 doesn't blink and doesn't get set to OUT.
I don't get any error messages.
int main(){
if (wiringPiSetupSys() == -1){
std::cout << "wiringpsetup failed\n";
exit(1);
}
auto pin = 17;
auto pin1 = 27;
pinMode(pin, OUTPUT);
pinMode(pin1, OUTPUT);
for (auto i = 0; i < 8; ++i)
{
digitalWrite(pin, HIGH);
digitalWrite(pin1, HIGH);
delay(500);
std::cout << "high\n";
digitalWrite(pin, LOW);
digitalWrite(pin1, LOW);
delay(500);
std::cout << "low\n";
}
}
However, I can make the LED on pin 27 blink by executing the following commands in the terminal:
gpio -g mode 27 out
gpio -g write 27 0
gpio -g write 27 1
gpio -g write 27 0
Consequently, the LED is properly connected and not broken.
A little additional information:
pi#raspberrypi:~$ gpio -g readall
+-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| | | 3.3v | | | 1 || 2 | | | 5v | | |
| 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5v | | |
| 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | |
| 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 0 | IN | TxD | 15 | 14 |
| | | 0v | | | 9 || 10 | 1 | IN | RxD | 16 | 15 |
| 17 | 0 | GPIO. 0 | OUT | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 |
| 27 | 2 | GPIO. 2 | OUT | 1 | 13 || 14 | | | 0v | | |
| 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 0 | IN | GPIO. 4 | 4 | 23 |
| | | 3.3v | | | 17 || 18 | 0 | OUT | GPIO. 5 | 5 | 24 |
| 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | |
| 9 | 13 | MISO | IN | 0 | 21 || 22 | 1 | OUT | GPIO. 6 | 6 | 25 |
| 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 |
| | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 |
| 0 | 30 | SDA.0 | IN | 1 | 27 || 28 | 1 | IN | SCL.0 | 31 | 1 |
| 5 | 21 | GPIO.21 | IN | 1 | 29 || 30 | | | 0v | | |
| 6 | 22 | GPIO.22 | IN | 1 | 31 || 32 | 0 | IN | GPIO.26 | 26 | 12 |
| 13 | 23 | GPIO.23 | IN | 0 | 33 || 34 | | | 0v | | |
| 19 | 24 | GPIO.24 | IN | 0 | 35 || 36 | 0 | IN | GPIO.27 | 27 | 16 |
| 26 | 25 | GPIO.25 | IN | 0 | 37 || 38 | 0 | IN | GPIO.28 | 28 | 20 |
| | | 0v | | | 39 || 40 | 0 | IN | GPIO.29 | 29 | 21 |
+-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+
| BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM |
+-----+-----+---------+------+---+---Pi 3B--+---+------+---------+-----+-----+
I still don't know why it doesn't work in the example, but I found another solution:
Instead of wiringPiSetupSys() I use now the function wiringPiSetupPhys() and accordingly the correct pins (13 and 15).
If someone knows a solution with wiringPiSetupSys(), I would still be glad about an answer...

How to Compare Averages of Categories

I have 3 tables:
table1:
Category
--------
1
2
3
4
table2:
Branch | Category
------------------
A1 | 1
A2 | 1
A3 | 2
A4 | 3
A5 | 4
A6 | 4
A7 | 4
table3: Values
Date | Branch | Value
---------------------------
1/1/2019 | A1 | 35
1/1/2019 | A2 | 40
1/1/2019 | A4 | 62
1/1/2019 | A5 | 10
1/1/2019 | A6 | 20
1/1/2019 | A7 | 35
Table Connections are:
Category -->--- Branch
and
Branch -->-- Values
I am trying to compare the value of every Branch with the average of the Category that belongs to. If the value of the Branch is below Category's average then it is good else is bad.
If I create a matrix with Branch, value and Category Average
it looks like this :
Branch | Value | Category Average
-------------------------------------
A1 | 35 | 35
A2 | 40 | 40
A4 | 62 | 62
A5 | 10 | 10
A6 | 20 | 20
A7 | 35 | 35
BranchAVG = AVERAGE(Table3[Value])
CategoryAVG = AVERAGEX(VALUES(Categories[Category]);[BranchAVG])
But it should look like this:
Branch | Value | Category Average | Good/Bad
------------------------------------------------
A1 | 35 | 37.5 | Good
A2 | 40 | 37.5 | Bad
A4 | 62 | 62.0 | Good
A5 | 10 | 21.7 | Good
A6 | 20 | 21.7 | Good
A7 | 35 | 21.7 | Bad
Is there any possible way to do that?
Thanks in advance
Elias
You can do this by adding a Category column to your Value table:
Category = RELATED(Branch[Category])
And after this add the AgeragePerCategory column:
AgeravePerCategory = CALCULATE(AVERAGE('Values'[Value]);FILTER('Values'; 'Values'[Category] = EARLIER('Values'[Category])))
Thanks for the answer.
To work it out I had to add an additional filter to Date, because it averages all values regardless the date.
So the AveragePerCategory it looks like:
AveragePerCategory = CALCULATE(AVERAGE('Values'[Value]);FILTER('Values'; 'Values'[Category] = EARLIER('Values'[Category]) && 'Values'[Date] = EARLIER('Values'[Date])))

After appending, I get null values in primary table headers

I have a table that I want to use as headers for another table that just has data. I used append as new in PBI, used the headers table as primary and data table as secondary. All the columns from the primary table have null values and the data table is appended next to headers column.
Eg:
Table 1 ( Headers)
+-----+-----+-----+-----+
| ABC | DEF | IGH | KLM |
+-----+-----+-----+-----+
Table 2 ( Data )
+----+----+----+----+
| 1 | 2 | 3 | 4 |
| 6 | 7 | 8 | 9 |
| 11 | 12 | 13 | 14 |
| 16 | 17 | 18 | 19 |
| 21 | 22 | 23 | 24 |
| 26 | 27 | 28 | 29 |
| 31 | 32 | 33 | 34 |
+----+----+----+----+
Table I am getting after append:
+------+------+------+------+------+------+------+------+
| ABC | DEF | IGH | KLM | null | null | null | null |
+------+------+------+------+------+------+------+------+
| null | null | null | null | 1 | 2 | 3 | 4 |
| null | null | null | null | 6 | 7 | 8 | 9 |
| null | null | null | null | 11 | 12 | 13 | 14 |
| null | null | null | null | 16 | 17 | 18 | 19 |
| null | null | null | null | 21 | 22 | 23 | 24 |
| null | null | null | null | 26 | 27 | 28 | 29 |
| null | null | null | null | 31 | 32 | 33 | 34 |
+------+------+------+------+------+------+------+------+
Table I need:
+-----+-----+-----+-----+
| ABC | DEF | IGH | KLM |
+-----+-----+-----+-----+
| 1 | 2 | 3 | 4 |
| 6 | 7 | 8 | 9 |
| 11 | 12 | 13 | 14 |
| 16 | 17 | 18 | 19 |
| 21 | 22 | 23 | 24 |
| 26 | 27 | 28 | 29 |
| 31 | 32 | 33 | 34 |
+-----+-----+-----+-----+
I used Append as new in PBI
Used the headers table ( Table 1) as primary and appended Table 2 to it.
This shows at the top function:
= Table.Combine({Table 1, Table 2})
This in the advanced editor:
let
Source = Table.Combine({Sheet1, InterviewQn})
in
Source
Expected result:
+-----+-----+-----+-----+
| ABC | DEF | IGH | KLM |
+-----+-----+-----+-----+
| 1 | 2 | 3 | 4 |
| 6 | 7 | 8 | 9 |
| 11 | 12 | 13 | 14 |
| 16 | 17 | 18 | 19 |
| 21 | 22 | 23 | 24 |
| 26 | 27 | 28 | 29 |
| 31 | 32 | 33 | 34 |
+-----+-----+-----+-----+
OR
+-----+-----+-----+-----+
| ABC | DEF | IGH | KLM |
| 1 | 2 | 3 | 4 |
| 6 | 7 | 8 | 9 |
| 11 | 12 | 13 | 14 |
| 16 | 17 | 18 | 19 |
| 21 | 22 | 23 | 24 |
| 26 | 27 | 28 | 29 |
| 31 | 32 | 33 | 34 |
+-----+-----+-----+-----+
If you're only trying to rename the columns of Table 2, using the column names of Table 1, then it's simply:
= Table.RenameColumns(#"Table 2", List.Zip({Table.ColumnNames(#"Table 2"), Table.ColumnNames(#"Table 1")}))
See https://pwrbi.com/so_55529969/ for worked example PBIX file

Power BI DAX to filter common items A & B share

Sample data:
| Vendor | Size Group | Model | Quantity | Cost | TAT | Posting Date |
|--------|------------|-------|----------|-------|-----|-------------------|
| A | S | A150 | 150 | 450 | 67 | July 7, 2018 |
| A | M | A200 | 250 | 1500 | 75 | June 22, 2018 |
| A | M | A150 | 25 | 8500 | 85 | July 9, 2018 |
| C | L | A200 | 350 | 1250 | 125 | March 5, 2018 |
| C | XL | A500 | 150 | 6500 | 45 | February 20, 2018 |
| A | M | A900 | 385 | 475 | 40 | January 29, 2018 |
| A | M | A150 | 650 | 45 | 45 | August 31, 2018 |
| D | M | A150 | 65 | 7500 | 15 | April 10, 2018 |
| D | M | A300 | 140 | 3420 | 10 | April 3, 2018 |
| E | S | A150 | 20 | 10525 | 85 | January 3, 2018 |
| B | S | A150 | 30 | 10500 | 40 | June 3, 2018 |
| B | S | A150 | 450 | 450 | 64 | April 3, 2018 |
| E | XS | A900 | 45 | 75 | 60 | January 3, 2018 |
| F | M | A900 | 95 | 655 | 175 | January 3, 2018 |
| D | XL | A300 | 15 | 21500 | 25 | January 3, 2018 |
| D | S | A500 | 450 | 65 | 25 | May 3, 2018 |
| A | M | A350 | 250 | 450 | 22 | January 3, 2018 |
| B | S | A150 | 45 | 8500 | 28 | January 3, 2018 |
| A | S | A300 | 550 | 650 | 128 | January 3, 2018 |
| C | M | A150 | 1500 | 855 | 190 | January 3, 2018 |
| B | M | A150 | 65 | 1750 | 41 | January 3, 2018 |
| A | L | A500 | 75 | 1700 | 24 | January 3, 2018 |
| B | S | A900 | 55 | 9800 | 37 | May 29, 2018 |
| B | M | A500 | 150 | 850 | 83 | April 18, 2018 |
In the provided sample, the common Size Groups A & B both share are S & M. So, I was hoping to display those Size Groups as the legend and Average Cost as the value in a clustered column chart.
Can anyone please advise how I can go about this?
Thank you!!!

Sort by two or more variables

I'm trying to sort by ID and then by Date.
What I have:
| ID | Date |
| ----------------------|
| 112 | 2013-01-01 |
| 112 | 2013-01-15 |
| 113 | 2012-01-01 |
| 112 | 2014-02-13 |
| 112 | 2013-01-02 |
| 113 | 2011-01-11 |
What I need:
| ID | Date |
| ----------------------|
| 112 | 2013-01-01 |
| 112 | 2013-01-02 |
| 112 | 2013-01-15 |
| 112 | 2014-02-13 |
| 113 | 2011-01-11 |
| 113 | 2012-01-01 |
My problem is that I only know how to sort by ID or Date.
More generally:
clear
input id foo
1 56
1 34
2 13
1 67
1 22
2 89
2 61
2 76
end
sort id (foo)
list, sepby(id)
+----------+
| id foo |
|----------|
1. | 1 22 |
2. | 1 34 |
3. | 1 56 |
4. | 1 67 |
|----------|
5. | 2 13 |
6. | 2 61 |
7. | 2 76 |
8. | 2 89 |
+----------+
In a more advanced programming context you can use the same syntax with bysort.